Walgreens’ quarterly results topped Wall Street’s expectations, even as profit declined from a year earlier.