Consistently buying shares of growing companies is a proven way to build lasting wealth in the stock market. The following companies would make great stocks to hold over the next few decades to protect and build wealth for a happy retirement.

1. Costco Wholesale

Costco Wholesale (COST -3.82%) is a no-brainer stock to hold for the long term. The business operates on razor-thin margins, which keeps competitors at bay. Costco operates on such low margins that half of its operating profit is generated from its annual membership fees. This allows the company to sell a range of quality goods, including high-end jewelry, at discounted prices.

Costco does discount retail better than anyone, which is the main source of its competitive advantage. It only stocks items that it can sell quickly to keep inventory turnover up. This instills a loyal customer base, as noted by its 90%-plus membership renewal rates.

With inflation starting to cool, the business is seeing improving sales trends. In the May-ending fiscal third quarter, Costco reported an increase in comparable store sales of 6.5%, excluding changes in gas prices and currency. But the 7.2% increase in the month of July suggests sales are accelerating.

Longer-term, Costco still has tremendous growth potential. The company plans to open new warehouses in Japan and Korea, but it's also finding ways to reach new customers in the U.S. through services like Uber Eats. Costco recently expanded the partnership with Uber to include more states and international countries, which could become an important customer acquisition tool.

Costco stock is up 62% over the last 12 months and trades at a high price-to-earnings ratio relative to expected earnings growth, but investors who regularly buy shares, or dollar-cost average, can profit off Costco's future growth without worrying about whether the stock is too expensive right now. The stock should be worth a lot more in 20 years than it is today.

2. Cava Group

Investors who park some cash in Cava Group (CAVA -2.79%) stock could see phenomenal returns over the next 20 years. Its Mediterranean-focused menu is standing out in an industry that is dominated by burgers and fries. The stock has returned 160% over the last year, but it's just getting started.

Despite a sluggish consumer spending environment, Cava posted an impressive 14% year-over-year increase in comparable sales last quarter. That helped push its total revenue up 35% over the year-ago quarter.

Importantly, Cava is already earning healthy margins to fuel shareholder returns. Restaurant-level profit margins are expected to come in at over 24% in 2024. In the second quarter, Cava's net income tripled year over year to $19.7 million on $231 million of revenue. Further expansion in Cava's relatively small restaurant base will drive higher profits and shareholder returns.

Management is investing in technologies, including generative artificial intelligence (AI), to make restaurants more efficient, and therefore, more profitable over the long term. These investments, along with its healthy margins and focus on speedy order delivery, show a lot of similarities between Cava and Chipotle Mexican Grill -- one of the best-performing and profitable restaurant brands.

With only 341 restaurants open, Cava offers years of above-average growth. As it opens more restaurants, strong revenue and earnings growth should send Cava stock to more new highs over the next 20 years.