The stock market is a fantastic vehicle for building long-term wealth. Over the last 40 years, the broad S&P 500 index has returned over 3,670%, but some unstoppable companies have performed even better. Investors who purchased Microsoft at its initial public offering (IPO) in 1986 would be sitting on a 308,000% gain today, for example. 

Earning astronomical returns requires some vision; investors need to assess which industries could dominate the future, and then buy stocks that are likely to benefit from those trends. In this instance, it's possible the metaverse and electric vehicles (EVs) could be the most transformative technologies of the next two decades.

Here are two stocks leading the charge in those businesses, and they could be the largest companies in the world by 2040.

A person wearing a virtual reality headset.

Image source: Getty Images.

1. The case for Meta Platforms

Formerly known as Facebook, Meta Platforms (META -0.77%) is a social media pioneer. The global population currently stands at 7.9 billion people, and 2.9 billion of them are using one of Meta's platforms each month, whether it's Facebook, Instagram, or WhatsApp. But despite its overwhelming success in the screen-based social media industry, the company envisions a slightly different future for itself.

Meta rebranded itself in 2021 to reflect its new focus on the metaverse. This virtual-reality world offers so many diverse opportunities that its impact on businesses could be as significant as the internet. Meta Platforms' users are set to exist as avatars of themselves, with the ability to teleport to different experiences and hold an inventory of digital goods. That's where the financial rewards might be, as the virtual world could sustain its very own digital economy.

Meta wants to build the architecture of the metaverse in much the same way it built its social media ecosystems. This would give the company an ability to earn revenue on all transactions that occur within it, and that's a level of dominance greater than it has even now. But it could be a software and a hardware story for Meta, as it already owns the Oculus brand, which makes virtual reality (VR) headsets.

Some estimates suggest the metaverse could be an $800 billion opportunity by 2024, but the kicker is its 12.4% compound annual growth rate (CAGR). It implies that by 2040, assuming the CAGR remains constant, the metaverse could be worth $5.1 trillion per year to companies like Meta Platforms. Since the company is projected to generate $140 billion in revenue in 2022, the potential upside by 2040 could therefore be enormous. 

A person at a car charging station, about to plug the charger into their electric vehicle.

Image source: Getty Images.

2. The case for Tesla

Data suggests that EVs represented 4.2% of all car sales globally during 2021, up from 2.5% in 2019. But according to The New York Times, they could soar to 25% of total sales by 2035, and 60% of total sales by 2050. 

That's great news for EV leader Tesla (TSLA -0.62%) because it means its addressable market would rise at least fivefold by 2040, with plenty of upside. It produced over 930,000 cars during 2021 and generated $47 billion in revenue, so this rapidly expanding market opportunity could see the company remain one of the largest in the world.

But the key difference between Tesla and other automakers is the company's gross profit margin, which came in at 25.3% for 2021. By comparison, Ford has a gross margin of about 14%, and that supports the argument that Tesla is closer to a technology company than simply a car manufacturer, hence its premium stock valuation compared to Ford. Tesla's bottom line, represented by its earnings per share, soared 203% year over year to $6.78 in 2021.

A separate argument for its status as a tech stock is the diversity of its businesses. In 2016, it acquired SolarCity, which paved the way for Tesla's expansion into energy generation and storage in new markets like residential housing. And given CEO Elon Musk's high-ranking position at SpaceX, a leading innovator in space technology, there's no telling where Tesla could expand next. 

Its powerful financial performance aside, Tesla is the ultimate future-tech organization, and although it's already the sixth-largest company in the world by market cap, it might have a clear view of the very top spot by 2040.