While most oil companies are struggling to keep the lights on, one firm has managed to prosper. On Tuesday, Valero Energy (NYSE:VLO) reported better-than-expected quarterly earnings, sending the stock higher at the opening bell. It's an odd development because most of the news out of the energy industry has been sour in recent months.

How has the company been able to pull this off? Can shareholders expect more gains in the months to come? For clues, let's dig a little deeper into Valero's most recent earnings report.

A look at the numbers
Energy companies are easy to wrap your head around. When oil and gas prices are high, their margins and their share prices can soar. But when energy prices are low, like they are today, their profits can plummet.

However, refiners like Valero are different. These companies make their money by exploiting the crack spread -- industry lingo for the price difference between a barrel of oil and refined products like gasoline and diesel.

In recent months, Valero has been making money hand over fist because this spread continues to widen. Low crude prices allow refiners to purchase their feedstock at a discount, enabling them to work in wider margins than they could otherwise earn. 

This was the biggest factor in the company's financial results. On Tuesday, Valero reported a first-quarter profit of $964 million, or $1.87 a share. That was up from $828 million, or $1.55 a share, a year earlier.

"Our team's solid performance and favorable margins helped us deliver impressive results during a heavy planned-maintenance period in the first quarter," said Valero Chairman, President and CEO Joe Gorder in a news release. "We continue to pursue operations excellence, which is the foundation for safe, reliable, and profitable operations."

Big investments in the company's business are also paying off. During the quarter, Valero refined 2.7 million barrels, on average, each day, an increase of 9,000 barrels per day from a year earlier. This has allowed the company to take advantage of higher world-market prices for gasoline and other refined products.

Valero is also finding creative ways to create value for shareholders. Since January, management has transferred more than $690 million in midstream assets -- activities involved in the processing, storing, and transportation of energy products -- to Valero Energy Partners (NYSE: VLP), the company's master limited partnership.

This could unlock a tremendous amount of value. These midstream properties tend to generate stable, reliable dividends. That's why income-hungry investors are willing to pay a big premium for them as stand-alone entities. 

In addition, executives also hinted that they are evaluating a share buyback program or further dividend hikes. In January, management hiked the company's quarterly distribution 45%, to $0.40 a share. Another payout increase could be a catalyst for the stock and a big vote of confidence in Valero's future. 

A look ahead
However, there were some problems in this report. Profits from the company's ethanol business came in at a meager $12 million last quarter, down from $243 million a year ago. The weakness was blamed on tighter margins, driven by a drop in ethanol rates that more than offset a decline in corn prices.

"Ethanol margins compressed in the first quarter of 2015, [though] they have rebounded some here in April." said John Locke, Executive Director of Investor Relations during the conference call. "Longer term we believe ethanol remains a key component of the transportation fuel mix."

Valero is putting on a brave face, but the company's ethanol business is looking shaky. Low gasoline demand has caused refiners to bump up against the dreaded "blend wall" -- the point at which more ethanol can't be safely blended into the fuel supply. This could put the brakes on the industry's growth for the foreseeable future. 

Foolish bottom line
In spite of the turmoil in the oil business, this company shows no signs of slowing down. A wide crack spread means Valero should be cranking out oversized profits for many quarters to come. For shareholders, that should translate into a higher stock price -- and juicy dividend hikes -- in the months ahead.

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.