Amidst a falling stock market, keep a particular eye on declining dividend stocks. Not only could they be potential deals, but investors also have the opportunity to secure higher-than-usual dividend yields. If a company's business isn't in trouble and the dividend is safe, a beaten-down stock could make for an excellent long-term investment.

Walgreens Boots Alliance (WBA -0.23%) is an intriguing stock for these reasons. Its shares have plummeted more than 30% in the past year (the S&P 500 is down just 13%), and the healthcare stock is now trading around where it was 10 years ago. Has it become a steal of a deal?

The case for buying Walgreens

Walgreens stores have benefited from an uptick in traffic over the past few years because its locations have been convenient places for people to receive COVID-19 vaccinations. And the pharmacy retailer is looking to give its customers more reasons to visit its stores. One such way is through a $5.2 billion investment in primary care company VillageMD. Walgreens is planning to launch hundreds of clinics at its stores, which could make them one-stop shops for healthcare services.

Walgreens has also been slashing expenses through its transformational cost-management program, and it expects to achieve $3.5 billion in annual cost savings before the end of fiscal 2024 (its year ends in August). That could go a long way toward boosting its profit and making it an even more attractive buy than it is today. At a forward price-to-earnings multiple of 7, Walgreens is trading at a steep discount (the average healthcare stock trades at 15 times its future profits).

Its business is pursuing growth and cutting costs, and it still pays a high dividend that yields 5.4% (the S&P 500 average is just 1.7%). Walgreens also raised its payouts in July by 0.5%, marking the 47th straight year in which it has increased its dividend payments. And with a payout ratio of around 30%, there's still room for more rate hikes in the future.

The case against Walgreens

Over the past decade, Walgreens' stock performance has been virtually flat -- down 2% (not including dividends) -- and so it has been an awful investment when compared to the S&P 500, which has climbed nearly 180% during the same time frame. The company simply hasn't generated much growth, and it hasn't offered a good reason for investing in its business beyond a decent dividend.

There's also the looming concern that Amazon and Walmart are taking a greater interest in the healthcare industry. Amazon recently announced plans to acquire primary care company One Medical, which could potentially pose a threat to Walgreens' plans for expansion. Walmart, meanwhile, has been rolling out low-cost healthcare services, and it could end up being the preferred one-stop shop for customers.

The pharmacy retailer's razor-thin margins will be tested by its expansion plans, inflation, and potentially rising competition from Amazon and Walmart. Walgreens' net income over the trailing 12 months totaled $5.4 billion and was just 4% of revenue ($134.5 billion). There's not much room there for Walgreens to absorb an increase in costs and still remain profitable.

Should you buy the stock?

Walgreens has a challenging path ahead, and the cost-reduction program will certainly help. Ultimately, a lot will depend on whether its investment in primary care pays off. If it does, Walgreens should do well. I'm optimistic that it can succeed, as it has the advantage of already being a trusted neighborhood pharmacy.

Amazon's recent decision to abandon its telehealth business, Amazon Care, suggests that it might have underestimated how difficult it is to penetrate the healthcare industry. And Walmart Health is only in two dozen locations right now, which is not likely to put a big dent in Walgreens' business immediately.

There's some risk with Walgreens today, but overall, it could make for a great contrarian buy. Its low valuation offers investors a margin of safety because the sell-off this year looks uncalled for; some investors are likely shunning the stock because the impact COVID-19 had on its business -- driving increased traffic -- might not be sustainable. But Walgreens' business isn't broken by any means, and its stock looks like an undervalued find to invest in today.