Valero Energy (NYSE:VLO) reported on Wednesday a narrowed fourth-quarter loss, as a rebounding economy helped the company rediscover impressive margins.

The San Antonio, Texas-based company posted a net loss of $438 million, or 77 cents a share, compared with a loss of $1.41 billion, or $2.51 a share, in the same quarter last year.

Earnings took a hit from the sale of the company’s interest in Cameron Highway Oil Pipeline Company. But excluding one-time items, Valero earned 32 cents a share, slightly below average analyst estimates polled by Thomson Reuters of 34 cents.

Operating income was helped by a 49% increase in refining throughput margins, due primarily to higher margins for diesel and gasoline coupled with better discounts for heavy-sour feedstocks.

“What a difference a year makes, said Valero CEO Bill Klesse. “Refining margins and crude oil discounts have improved substantially over the past year, and this market momentum has carried into 2011.”

Revenue for the petroleum refiner was $22.16 billion, up from $17.8 billion a year ago, narrowly beating the Street’s view of $21.12 billion.

Retail and ethanol sales surged during the quarter, with retail growing to $61 million, nearly matching its full-year record results in 2008. Ethanol climbed to $70 million during the quarter, and set a record high with $209 million for the full-year.

Looking ahead, the nation’s largest refiner said it would focus on safety, improving reliability, achieving another $100 million in pre-tax cost savings and executing its growth projects.