Oil that's over $110 a barrel because of war in eastern Europe suddenly has a lot of people looking at oil stocks. But savvy investors have been eying the sector for some time, and are seeing the depressed valuations of producers as an opportunity.

The long-term outlook for oil and gas remains positive because of how ingrained fossil fuels are in our economy. You can't just stop drilling without causing an economic collapse, and renewables come with their own limitations.

Crew working on  an oil rig.

Image source: Getty Images.

Energy prices were soaring before the outbreak of hostilities in Ukraine, but the response to the war will carry its own impact. Shell, for example, announced it was exiting from all Russian operations, including its partnership with Russian state oil giant Gazprom, which could lead to as much as $3 billion in impairments. BP is divesting its near-20% stake in Russia's Rosneft, resulting in a massive charge of around $25 billion. Their stocks might be stunted for many quarters to come as a result.

The two oil and gas producers below, however, represent the best long-term opportunities in the space.

Worker at illuminated offshore oil rig.

Image source: Chevron.

Chevron

Spiraling oil prices are helping Chevron (CVX 0.37%) enjoy record-high cash flows, which it is using to shore up its balance sheet and buy back more stock. It's committed to repurchasing between $5 billion and $10 billion worth every year, while capping capital expenditures at $17 billion annually through 2026, about half the rate it previously spent.

While Chevron's operations are global in nature, with over 60% of its production coming from outside the U.S., because it does not have exploration and production operations in Russia it is shielded more than its rivals from the events unfolding in Ukraine. Wirth told analysts "We are relatively less affected, I think, than most others in the industry."

However, its Caspian pipeline is majority owned by Russia (Chevron has a 15% stake) and it carries oil from Kazakhstan through Russia to the Black Sea. At only 4% of upstream earnings, though, and less than 3% total earnings, should those supplies be cut off it shouldn't hurt Chevron greatly.

Earlier this year Chevron raised its dividend 6% to $1.42 per share, more than analysts had expected. The oil producer has increased its payout for 35 consecutive years, firmly placing it in the ranks of Dividend Aristocrats. In all, cash returned to shareholders is expected to grow more than 50% from last year.

So long as oil remains above $60 a barrel, investors can look forward to Chevron growing its operating cash flows by 10% annually through the middle of the decade.

Offshore oil rig platform.

Image source: ExxonMobil.

ExxonMobil

ExxonMobil (XOM -2.78%) has operated in Russia for over 25 years through a 30% stake in three large offshore oil fields off of Sakhalin Island, and had been planning to build a liquified natural gas plant there. But the energy company has suspended all operations in response to the invasion and said it will no longer make new investments in the country.

Given that Rosneft is a partner in the operations, which have produced over 1 billion barrels of oil and 1 billion cubic feet of natural gas since 2005, pulling out of the partnerships will hurt, but not nearly as much as others will feel because Exxon's ties to the country are relatively small compared to the rest of its global operations.

Its portfolio of energy assets is impressive -- the largest segment, oil and gas production, posted $6.1 billion in operating profits last month. As a result, Exxon will increase its production in the U.S. Permian basin by 25%, and after adding an extra vessel to increase capacity to over 340,000 barrels per day in Guyana, Exxon expects capacity to reach 800,000 barrels in three years' time.

The Liza Phase 2 project in Guyana will add 100,000 barrels per day, with a break-even point at $32 per barrel. Exxon has lowered its overall break-even point to just $35, and while oil has been volatile enough over the years, it's clear the oil and gas producer will be reaping significant profits for some time to come. Profits have also improved in its refining segment.

Exxon is maintaining its commitment to returning value to shareholders as well. It intends to buy back $10 billion worth of stock, and also raised its dividend, tacking on another year in its 39-year run of increasing the payout. These are just some of the reasons ExxonMobil is my top oil stock to buy now, and one to consider owning for the long haul.