Now that we've had some time to digest Valero Energy's (NYSE:VLO) second-quarter earnings, let's ask the most important question for long-term investors: Is now the time to buy the stock?

The past two quarters haven't been kind to oil refiners because of breathtakingly low refining margins, so you're certainly justified to feel skittish. Despite the low margins, though, Valero has managed to maintain impressive operations while displaying good financial discipline. In all, it looks like a great time to buy for the future. Here's why.

Valero's balance sheet

There were really two key takeaways from Valero's second-quarter earnings. First, the company beat earnings expectations and reported $503 million in adjusted net income. Second, the company managed these earnings despite low refining margins. In fact, when combined, Valero's first- and second-quarter margins are the lowest the company has experienced since the two-quarter period spanning the end of 2011 and beginning of 2012 .

Despite these difficult conditions, caused by oil-price volatility and an abundance of stored petroleum products, Valero's balance sheet remained pretty solid. Its debt-to-capitalization remained within its 20% to 30% target range at just under 27%. Its net cash from operating activities in the second quarter were over $2.3 billion. And its cash and investments approached $5 billion.

This financial discipline and flexibility is critical for a company that's so heavily affected by refining margins, which Valero expects to remain low for the rest of 2016. It's also important for the company to continue to improve and strategically expand its operations, which is exactly what it's been doing.

Recent acquisitions and investments

In late June, Valero used its extensive cash positions to purchase 50% of the Parkway pipeline from Kinder Morgan, giving it 100% ownership. The pipeline, with 110,000-barrel-per-day capacity, transports petroleum products from Valero's 305,000-barrel-per-day St. Charles refinery to Kinder Morgan's Plantation pipeline in Mississippi. Valero can expand the capacity of the parkway system to 200,000 barrels per day.

Additionally, Valero completed an agreement to build a new lateral segment to connect to the Colonial pipeline system. In total, the purchase allows Valero to distribute refined products to a significant portion of the Eastern United States. Valero touts the capital discipline of these moves, where the "acquisitions are strategic to Valero's core business and investments are consistent with our strategy to grow our logistics assets."

Further growing its core business, Valero also completed the expansion of its Houston refinery, adding an additional 90,000 barrels per day in capacity. The facility, which started up in June, should increase exports from its key refinery base in the Gulf.

Time to buy

As the company points out, these investments -- and the entirety of its 2016 capital program of $2.6 billion -- are focused on long-term earnings growth. That fact, along with relatively strong earnings despite the current environment, makes it slightly surprising to see Valero continuing to trade near 52-week lows .

It's possible that the low price is driven by Valero's significantly reduced revenues and income compared with 2015, when refining margins were much higher. It's also possible that the potential for low margins for the rest of 2016 has scared off potential investors.

Regardless, the company's trailing price-to-earnings ratio remains lower than that of some of its industry competitors, making it appear cheap. Additionally, Valero continues to reward investors with a high dividend yield and share buybacks, staying committed to returning 75% of net income to investors this year.

Valero has proved it can profitably maintain high throughput capacities even with low margins. There's no reason to believe it can't maintain that type of success long-term. With strong earnings in a difficult environment, a high dividend, and a rock-solid balance sheet, Valero definitely looks like a buy.

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.