Warren Buffett, the world’s greatest investor once famously stated, “Only buy something that you’d be perfectly happy to hold if the market shut down for 10 years.”

I couldn’t agree more with his sentiments on long-term investing.

Too many investors chase hot stocks, market headlines, and trade far too frequently, causing them to incur unnecessary losses and higher broking costs that eat in to their returns.

However, to be successful at long-term investing, it takes more than just buying and holding a stock for a considerable period. It is also important to identify companies that have solid economic moats, offer timeless products or services, have above average profitability, and have the ability to grow earnings.

Let’s take a closer look at two companies that possess those attributes and more, making them ideal stocks to buy and hold forever.

Now what?

It is hard to get past Canadian National Railway Company (TSX:CNR)(NYSE:CNI). The operator of Canada’s only transcontinental rail network has delivered an impressive windfall for investors with its share price having grown more than 30-fold since going public in late 1995.

Then there is its equally impressive history of dividend growth. It’s hiked its dividend every year since 1996 and now yields 1.7%. There are signs that this remarkable rate of growth can only continue because the attributes that allowed it to grow at such a strong rate remain in place.

You see, the breadth of its business coupled with steep barriers to entry for the rail industry, including significant regulations, endows Canadian National with a solid economic moat, protecting it from completion.

Furthermore, the demand for rail transportation remains stable as it is the only cost-effective means of transporting bulk freight across North America.

For these reasons its earnings will grow over the long term despite the short-term headwinds created by the commodities crunch.

The next stock is electric utility Emera Inc. (TSX:EMA).

Like all electric utilities, it possesses a wide economic moat because of the considerable barriers to entry to the industry. These include steep regulatory hurdles and the need to invest considerable amounts of capital in order to establish the required infrastructure to operate in the industry.

Then it is worth considering that the demand for electricity remains inelastic because it is an important part of our modern lives.

All of these characteristics virtually guarantee Emera’s earnings and have been the reason for its solid earnings growth in recent years.

For the third-quarter 2015 alone, net income shot up by an impressive 16% compared with the same quarter in 2014, while for the full-year 2014 net income almost doubled in comparison to 2013.

I expect this strong earnings growth to continue.

Emera’s US$10 billion acquisition of U.S.-based TECO Energy, which has 2.4 million electric and gas customers located across New Mexico and Florida, will give its bottom line a nice bump once completed.

As a result of this solid earnings growth Emera has rewarded investors with an impressive history of dividend hikes; it has increased its dividend for the last nine straight years to give it a juicy 4.5% yield.

So what?

The strategy of buying and holding stocks for the long term, if correctly executed, can deliver considerable windfalls for investors. Not only will they be rewarded by solid capital gains, but it will deliver an ever-growing and reliable income stream. Investing in companies such as Canadian National and Emera, which have solid moats and histories of regular dividend hikes, is the perfect way to implement this strategy.

Want more top dividend stocks?

These three top stocks meet the criteria to buy and hold forever, having delivered dividends for shareholders for decades (and even centuries!). Check out our special FREE report: "3 Dividend Stocks to Buy and Hold Forever". Click here now to get the full story!

NEW! This Stock Could Be Like Buying Amazon In 1997

For only the 5th time in over 14 years, Motley Fool co-founder David Gardner just issued a Buy Recommendation on this recent Canadian IPO.

Stock Advisor Canada’s Chief Investment Adviser, Iain Butler, also recommended this company back in March – and it’s already up a whopping 57%!

Enter your email address below to claim your copy of this brand new report, “Breakthrough IPO Receives Rare Endorsement.”

Fool contributor Matt Smith has no position in any stocks mentioned. David Gardner owns shares of Canadian National Railway. The Motley Fool owns shares of Canadian National Railway. Canadian National Railway is a recommendation of Stock Advisor Canada.