Oil stocks tend to be volatile due to uncertainties in the oil markets, which often experience elongated periods of boom and bust. Losing faith in the viability of oil and gas as an energy source and selling stocks when the markets aren't favorable can prove to be a costly mistake. If you plan to invest in energy stocks, you should have a long-term investment horizon.

Let's look at why keeping a long-term horizon is important and the top stocks you can buy and hold for the next decade and beyond.

Fluctuations in oil prices

Over the past two decades, Brent crude oil prices fluctuated significantly -- from over $120 per barrel to below $40 per barrel. Domestic benchmark West Texas Intermediate also moved largely in tandem with the global prices.

WTI Crude Oil Spot Price Chart

WTI Crude Oil Spot Price data by YCharts.

Indeed, profits that the integrated oil and gas companies, such as ExxonMobil (XOM 0.02%) and Chevron (CVX 0.44%), make when oil prices are $120 per barrel are quite different from those made if prices fall below $40 per barrel. The performance of oil and gas stocks over the last 10-year period was not impressive, largely due to low energy commodity prices.

XOM Total Return Price Chart

XOM Total Return Price data by YCharts.

As the chart shows, top oil and gas stocks -- ExxonMobil, Chevron, Kinder Morgan (KMI 0.27%), Williams Companies (WMB 1.21%), and Enterprise Products Partners (EPD 0.48%) -- underperformed the S&P 500 Index over this period. Notably, the chart starts in 2012, when oil and energy stock prices were very high. Still, the recent rise in energy stock prices has boosted the returns on these stocks back into the green.

Let's move back a little to see how energy stocks have fared over the last two decades. Kinder Morgan is eliminated because it didn't go public until 2011.

XOM Total Return Price Chart

XOM Total Return Price data by YCharts.

Chevron, Williams Companies, and Enterprise Products Partners outperformed the S&P 500 Index in total returns over the last 20 years. If we go back further, the top performers change again. Still, most stocks outperformed the market.

XOM Total Return Price Chart

XOM Total Return Price data by YCharts.

Notably, all five stocks outperformed the broader market in the last year.

XOM Total Return Price Chart

XOM Total Return Price data by YCharts.

The takeaway is that if you invest in strong, well-managed energy companies with diversified assets and hold the stocks long term, you'll generate handsome returns while diversifying your portfolio.

Top energy stocks

Chevron and ExxonMobil are among the largest integrated oil companies in the world. Both have been operating for decades, generating handsome returns for their shareholders. Both Chevron and ExxonMobil are Dividend Aristocrats, with Chevron raising its dividend for 35 years in a row and ExxonMobil for 39. Although some investors may prefer one over the other, there are several things to like about both.

If you don't like integrated oil stocks' volatile earnings and prices, you can consider companies operating in the midstream energy space. These companies are primarily involved in transporting and storing oil, gas, and natural gas liquids. Their earnings are relatively stable compared to oil and gas producers, as they typically generate fee-based cash flow based on volumes transported or stored.

Enterprise Products Partners, Kinder Morgan, and Williams Companies are among the top midstream stocks to consider buying now. Regular dividend income contributed significantly to the handsome total returns these stocks generated over years, as discussed above.

Enterprise Products Partners stock offers an attractive distribution yield of 6.9%. The company has been growing its dividend for 24 consecutive years and looks well placed to continue growing them in the years to come.

Kinder Morgan stock offers a dividend yield of 5.9%. The expected demand growth for natural gas offers visible growth opportunities for Kinder Morgan in the coming decades. At the same time, the company is looking to expand its operations in the renewable energy space. Likewise, Williams Companies is focused on high-return expansion projects, and the stock offers an attractive yield of 4.9%. In all, investing in these five energy stocks for the long term could significantly enhance your portfolio returns.