Oil prices tumbled at the beginning of 2020 and remained weak for the rest of the year. As a result, all major oil and gas companies took a big hit, with Royal Dutch Shell and BP forced to slash their dividends. Oil was written off as dead by many, and investors poured funds into renewable energy stocks, resulting in their sky-high valuations.

Come 2021, and the narrative has shifted big time. Strengthening oil prices have attracted investors back to oil and gas stocks. The SPDR Energy Select Sector ETF is up more than 40% while the Invesco Solar ETF is down 27% so far this year. So, as an energy investor, what should you do? Let's take a look at the key factors that you should consider, as well as three top energy stocks to invest in right now.

Renewables versus fossil fuels

Market sentiments aside, the fact is that focusing on only renewables or only fossil fuels is good neither for the world's energy needs, nor for your portfolio. Consider this: The U.S. Energy Information Administration projects renewables to surpass all other energy sources of global primary energy by 2050. The share of renewables is expected to rise to 28% in 2050 from 15% in 2018. But where will the remaining energy come from?

Young Boy Businessman Sits with U.S. Money Savings.

Image source: Getty Images.

Around 27% of the global primary energy needs are expected to be met from petroleum and other liquids, 22% from natural gas, and 20% from coal. So, oil and gas could still contribute nearly 50% to the world's primary energy needs by 2050. Of course, these projections could be off mark, but fossil fuels will play a key role in meeting global energy needs for decades to come. Scalability, cost, and consistency are among the top reasons fossil fuels cannot be replaced with renewables overnight. As an investor, it thus makes sense to keep invested in both renewable energy as well as oil and gas stocks.

Top solar stock: Enphase Energy

Among renewable energy stocks, microinverter supplier Enphase Energy (NASDAQ:ENPH) looks promising. All the company's key financial metrics are trending in the right direction.

ENPH Revenue (TTM) Chart

ENPH Revenue (TTM) data by YCharts

For the last three years, Enphase Energy's revenue and cash from operations have been on an upward trend. In the latest quarter, the company's revenue grew 47% year over year. The company reported healthy gross margin of 40.7% for the quarter. 

Though Enphase Energy faces significant competition that could strain its margin, the company has generated peer-leading margin and sales growth in the last couple of years. It has solidified its position as a top supplier of microinverters -- a key segment of the fast-growing solar industry.

Renewables-focused utility: Algonquin Power & Utilities

Algonquin Power & Utilities (NYSE:AQN) provides investors exposure to renewable energy while also offering steady income from its traditional utility operations. Roughly 70% of the company's earnings come from its utility operations while the remaining 30% is from renewable generation.

In the first quarter, one of Algonquin Power's wind facilities in Texas was impacted by extreme winter weather conditions, which affected its renewables earnings for the quarter. Despite that, the company increased its quarterly revenue by 36% over the same quarter last year while its adjusted EBITDA grew 17%. Growth in Algonquin's regulated utility earnings more than offset the decline in its renewables segment. 

The company's steady earnings have allowed it to raise its dividend consistently over time. In 10 years, Algonquin Power grew its dividend at a compound annual rate of 10%. In the latest quarter too, the company raised its dividend by 10%. Moreover, its $9.4 billion capital investments plan through 2025 should help it continue growing its dividends in the coming years. 

Top oil stock: ExxonMobil

Learning from the challenging times last year, ExxonMobil (NYSE:XOM) has created lots of flexibility in its capital plans and intends to adjust its capital spending to market conditions. The company reported better-than-expected performance in the first quarter, primarily driven by higher commodity prices. It announced earnings of $2.7 billion compared to a loss of $610 million in the year-ago quarter. 

ExxonMobil stock is up more than 50% so far this year. The stock therefore isn't as attractive as it was last year, or even two months back. Yet it currently offers an attractive dividend yield of 5.5%. Indeed, the stock can be volatile, moving with oil prices. However, the company has been keen on maintaining its dividend, even in challenging times. Long-term income investors would find ExxonMobil an attractive option to gain exposure to the oil and gas sector.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.