Image source: Getty Images.

Discovering a company that has the potential to last for decades and decades is incredibly challenging. If you need an example of this, imagine you travel back in time 30 or 40 years ago and you need to explain everything that an iPhone does today. The rapid advancement of technology and its impact on our everyday behavior is staggering. Now apply that to investing.

As challenging as it is to find an investment that will be successful over the long term, though, there are some stocks that look like they have the legs to last in a forever portfolio -- stocks that have rock-solid businesses behind them that should stand the test of time. Three that look compelling in this regard are Canadian National Railway (CNI 0.39%), Kroger (KR 1.80%), and Waste Management (WM 0.97%). Here's a quick look at why they appear to be suited for a buy-and-hold-forever kind of investor. 

Riding the rails to solid profits

As much as we have tried to improve on transportation and logistics over the years, the most cost-effective method of moving large quantities of goods is more than 200 years old: rail. According to the Bureau of Transportation Statistics, the average revenue per ton-mile for the most recent year of comparable results -- 2007 -- is 2.99 cents for rail versus 16.5 cents for truck or 89.7 cents for domestic airline carrier. Granted, that is a pretty old statistic, but rail has maintained much lower per-ton-mile costs than any other form of overland transportation. That, and the immense economic moat that railroad companies have, makes Canadian National Railway a compelling buy-and-hold-forever investment. 

The effectiveness of a rail company comes down to two factors: the size and scale of its network, which gives customers lots of options and variability in where to deliver goods, and operating efficiently, which minimizes downtime and cost. All of these things Canadian National has or does. Its 20,000 route miles of track is the only rail network in North America that connects the Atlantic, Pacific, and Gulf Coasts, and the company adeptly manages its operations to minimize yard time for cargo and maximize the amount of cargo each locomotive horsepower pulls. These elements make Canadian National a free-cash-flow-generating machine that management has used well to consistently raise its dividend and buy back gobs of stock to produce fantastic long-term returns.

CNI Dividend Chart

CNI Dividend data by YCharts.

At 18 times earnings, shares of Canadian National Railway aren't exactly cheap, especially considering that the rail industry in general is hitting a lull from declining shipments of coal. It may not be a stock to buy today, but certainly one to buy at the right price and hold on to forever.

Eggs, milk, and strong returns for years to come

If you grouped businesses according to the categories in Maslow's hierarchy of needs, the industries that catered to the most essential needs at the bottom of the pyramid would be ones that are hardest to disrupt. Physiological needs are crucial, or, put another way, we all gotta eat, right? Even though food is an essential part of our lives, it is almost shocking how challenging the grocery business actually is. Margins are razor-thin, and it is an area in which stellar management can make a huge difference. Success is not just tied to the meat-and-potatoes aspects of the business, like inventory management, but it is also about creating the right kind of store appearance and brand that will attract customers and make them return again and again. In the grocery business today, no one does it better than Kroger. 

In fact, this year is revealing as to why Kroger is one of the best operators in this fiercely competitive business. Falling food prices across the country have forced supermarkets and grocers into a heavier cycle of promotions that hit margins. Despite these challenges, Kroger's guidance for the year has been lowered by only 4% while some of its peers have estimated their end-of-year profits will be as much as 13% lower. The company has also used opportune times in the past to acquire some of its competitors and has maintained its streak of 51 straight periods of growing comps dating all the way back to 2004. 

KR Dividend Chart

KR Dividend data by YCharts.

A top-notch operator in an essential industry like food is one of those hold-forever kind of stocks. To put a cherry on top, Kroger's stock today looks like a pretty attractive investment. With shares hitting 52-week lows after a 19% pullback in 2016, Kroger's stock trades at a price-to-earnings ratio of just 14. That seems like a pretty modest price to pay for an investment in something as essential to our everyday lives as food.

One man's trash is another man's high-return investment

It's pretty hard to argue that humans won't need to move goods or require food, but there is an aftereffect of these two necessities that makes for another built-to-last business: waste handling. Waste handling, like rail, is an extremely hard business to disrupt. It requires immense amounts of capital to get off the ground, and the entrenched businesses have economies of scale that give them immense advantages over any new entrants. This is what makes Waste Management so compelling as a buy-and-hold-forever kind of investment: It takes those competitive advantages and manages the business into a high-return machine.

For waste companies, the name of the game is cost control. While up-front costs for aspects of the business like landfills are high, the everyday costs of concern are using and maintaining its waste-collection fleets. Waste Management found a rather creative way of managing those costs by converting its fleet to run on natural gas instead of diesel. Not only is natural gas a cheaper fueling option thanks to shale gas, but the company even collects the methane emissions from its landfills to run its fleet. These kinds of creative ideas have allowed the company to keep costs at bay and continually generate gobs of free cash flow and high returns on equity that it uses to reward shareholders with a decent dividend and lots of share repurchases. 

WM Dividend Chart

WM Dividend data by YCharts.

Chances are that no matter what kind of futuristic society we're living in 20,50, or 100 years from now, we will be generating refuse in some form or another. Furthermore, Waste Management looks to be the kind of business that will be around long enough to generate shareholder value over that long time frame. If you want to build a portfolio that lasts forever, Waste Management should probably be in it.