Investing in retail stocks has always been somewhat dangerous due to an abundance of competition in the sector. However, the rise of Amazon.com (AMZN -1.14%) has made retail an even more perilous place for long-term investors.

For many storied retail giants like Macy's (M 0.16%), comparable-store sales -- a key revenue metric that strips out store openings and closings -- began to decline in 2015, and haven't recovered. Persistent comparable-store sales drops have caused a sharp erosion in operating profit at Macy's, as well as at other department stores like Kohl's (KSS 4.53%). Investors are anxiously watching other retailers' comp sales trends, fearing that they could be Amazon's next victims.

To some extent, this caution is warranted. That said, the sell-off among department store stocks in particular has made companies like Macy's and Kohl's extremely attractive for value investors who are willing to be patient in the face of tough short-term trends.

The exterior of a Kohl's store

Kohl's is one of several retail stocks that appear to be severely mispriced. Image source: Kohl's.

Meanwhile, other segments of the retail landscape remain quite healthy. For example, home-improvement retailers are still seeing strong growth as more people look to remodel their homes. The potential demise of Sears Holdings (SHLDQ) will put more revenue up for grabs in key categories like appliances, tools, and lawn and garden. This could drive big gains for Lowe's (LOW -0.03%).

Cash is king at Kohl's

Last quarter, Kohl's posted surprisingly strong sales results, with comp sales up 0.1% year over year. This suggests that the company is making the right moves to drive traffic into its stores. Nevertheless, the stock remains almost 25% below its 52-week high, partly because earnings per share still slipped by double digits in the third quarter, missing the average analyst estimate by $0.02.

Investors shouldn't be too worried about the EPS decrease. The timing of sales during the quarter negatively impacted gross margin, while hurricanes Harvey and Irma combined to depress sales and drive up the company's costs. By contrast, sales have gotten off to a good start this quarter, including a strong Thanksgiving/Black Friday period.

Furthermore, free cash flow is a better metric of Kohl's earnings power than EPS. Kohl's has slowed its growth in the past couple of years, so it is spending less on capex than the noncash depreciation and amortization expense it reports in its earnings statement. The company is also reducing its inventory at a steady pace, boosting free cash flow.

Indeed, Kohl's 2016 free cash flow of $1.4 billion was more than double its adjusted net income. While that was an unusually strong result, free cash flow is on track to reach $1 billion again in 2017, which would far exceed the company's projected net income.

While Kohl's stock has rallied in recent months, the company's $7.5 billion market cap is still modest compared to its strong free cash flow production. Additionally, Kohl's is testing various initiatives to keep customers coming into its stores, such as an agreement to open Amazon smart home shops in certain stores and to handle returns for Amazon in the Chicago and Los Angeles markets. These are bold moves that could help Kohl's remain relevant, powering big gains for investors.

Macy's plots a comeback while monetizing real estate

Like Kohl's, Macy's has fallen out of favor with investors -- but it, too, is plotting a comeback. The department store icon recently rolled out a new loyalty program that incentivizes customers to spend more money at Macy's. It also plans to aggressively expand the Backstage off-price concept that it has been piloting in some of its less productive stores.

The exterior of the Macy's Herald Square flagship store in Manhattan

Macy's is working hard to stop a three-year sales slide. Image source: Macy's.

These moves could help Macy's stabilize its sales in the coming year, following nearly three years of steep sales declines. The company started strong this quarter, thanks to its sales growth initiatives and a dose of cold weather in the Northeast, although a credit card glitch that hit the retailer in the afternoon on Black Friday may have slowed its momentum.

However, the investment case for Macy's revolves around its real estate just as much as its retail operations. The company's real estate portfolio may be worth as much as $20 billion, nearly double Macy's current enterprise value.

Macy's has been selling noncore real estate at a steady pace since 2015, bringing in cumulative proceeds of more than $1 billion. It is also laying the groundwork for development projects at several dozen store sites, with plans likely to be announced next year. Finally, Macy's is looking at options for redeveloping part of its massive Manhattan flagship store.

Ideally, Macy's turnaround efforts will drive a rebound in sales and earnings. That would send Macy's stock soaring, given that it currently trades for just seven times the company's 2017 EPS forecast. However, even if the turnaround plan doesn't succeed, the company's real estate value provides a huge safety net for investors.

Lowe's is riding a rising tide of home-improvement projects

Whereas Kohl's and Macy's have been struggling to fend off competition from Amazon.com, the home-improvement category has been immune to e-commerce disruption so far. For example, in 2016, comp sales increased by 4.2% at Lowe's and 5.6% at The Home Depot.

To some extent, the home-improvement giants are simply in the right place at the right time. New home construction is rebounding, while Americans are pouring huge amounts of money into remodeling projects. This is driving strong growth in categories ranging from appliances (where Lowe's is the market share leader) to tools and building materials.

These trends will benefit Home Depot as well as Lowe's, but the latter is a more compelling investment opportunity right now for several reasons. First, it has a more reasonable valuation of 15 times forward earnings. Second, while Lowe's has a lower profit margin today, it may be able to narrow the gap over time.

Third, Lowe's is in particularly good position to benefit if Sears goes out of business in the next few years -- which seems likely to happen. Most notably, Sears' appliance business is still a multibillion-dollar revenue generator. As the top appliance seller in the U.S., Lowe's is sure to get a big share of the sales that Sears is giving up.

Lowe's also wants to be first in line to scoop up Sears' share of the tool market. Last month, the company announced that it will start selling tools and other products from the Craftsman brand, which was a Sears private brand until earlier this year.

Thus, Lowe's is well positioned to continue posting steady comp sales growth and double-digit EPS growth for years to come. Based on this strong outlook, the stock appears to have huge upside over the next few years.