A slew of retail stocks surged in early August, after various department store chains surprised Wall Street with better-than-feared earnings reports. Several department store stocks, including Macy's (M 0.50%), jumped 15%-20% in just a few days. Meanwhile, shares of off-price leader TJX Companies (TJX 0.31%) hit a new all-time high of $83.64.

However, both stocks have come back to earth in the past month. Macy's stock has given up nearly all of its post-earnings gains and is right back where it started the month of August. TJX stock has fallen more than 10% from its mid-August high.

M Chart

Macy's and TJX YTD Stock Performance, data by YCharts.

With shares of Macy's and TJX marked down again, this could be a good time to invest in both retail giants.

Macy's aims for a sales turnaround -- while selling off real estate

Since the beginning of 2015, Macy's has been contending with a series of comparable store sales declines. That streak continued last quarter, as Macy's comp sales fell 2%, including licensed departments. Yet that was far better than the 5.6% drop recorded in the first quarter of 2016.

Thus, while Macy's still has plenty of work to do to get comp sales growing again, it is at least on the right track. Macy's is experimenting with a variety of initiatives to drive more traffic to its stores, such as adding more dining options. To expedite a return to comp sales growth, it also expects to close nearly 15% of its full-line Macy's stores in the coming months.

Macy's will mainly close underperforming stores where sales and profitability appear to be in terminal decline. The company hopes to retain much of the sales volume from these stores at nearby locations and through its e-commerce site. Macy's also expects to close a handful of stores that sit on particularly valuable real estate.

The biggest real estate opportunities come from a few key downtown stores. Last month, Macy's revealed that it is in negotiations to sell its roughly 250,000 square foot men's store building in San Francisco. Based on the recent sale price of the nearby Saks Fifth Avenue men's store building, the Macy's building could be worth $400 million-$500 million.

Macy's is making progress on selling some of its valuable real estate. Image source: The Motley Fool.

Macy's is eager to sell, lease, or otherwise redevelop underutilized space in several other flagship stores. It will also opportunistically look to sell mall-based stores for redevelopment: a move that is increasingly attractive to mall owners.

The process of divesting real estate tends to be slow. However, it could ultimately represent a multi-billion dollar windfall for Macy's. Considering that the company's market cap is less than $11 billion, this is nothing to sneeze at.

TJX keeps rolling

While Macy's has been fighting severe sales pressure lately, TJX has had no such worries. Last quarter, the company reported 4% comp store sales growth. Earnings per share rose 5% year over year, in the face of ongoing labor cost pressure. TJX also raised its full-year EPS forecast.

Despite the strong results, TJX stock has fallen by about 10% in the past month. Several pundits have attributed the weak share price performance to TJX's Q3 and full-year guidance, which fell short of the average estimates published by Wall Street analysts. Investors should take this guidance with a grain of salt, though. TJX routinely provides conservative forecasts and then beats them by a mile.

In addition to delivering consistent comp sales growth, TJX is steadily adding new stores. The company currently sees the potential to grow its store count by more than 50% in the coming years, even without adding new store concepts or new markets. The resulting high single-digit revenue growth is allowing TJX to grow EPS while absorbing the impact of wage increases.

TJX still sees plenty of room to grow its store count. Image source: The Motley Fool.

TJX stock isn't especially cheap, trading for 21 times the company's projected 2016 EPS. Still, the company has earned its valuation premium through its history of steady sales and earnings growth.

TJX's management is likely to capitalize on the recent stock pullback by repurchasing more stock to drive faster EPS growth. The company recently issued $1 billion of debt, more than half of which will be available for buybacks. This gives TJX the financial firepower to reach the upper part of its $1.5 billion-$2.0 billion target range for share buybacks this year.

Two solid picks for different reasons

Macy's and TJX are two of the biggest apparel and home goods retailers in the U.S. Both stocks look like compelling investment opportunities after their recent pullbacks, though for different reasons.

Macy's stock is flat-out cheap, especially after taking into account the value of the real estate it plans to sell off. If Macy's can stabilize its comp store sales and recover some of its recent margin deterioration, the stock should rise dramatically in the next few years, despite the company's lack of growth opportunities.

By contrast, an investment in TJX is a bet on the company's long-term growth prospects. While rising labor costs represent a significant risk, TJX should be able to offset that pressure if it can keep sales rising quickly. So far, it shows no signs of slowing down.