Supervalu (SVU) turned a profit in the second quarter, thanks to lower costs and improved margins for the grocery chain.

The company reported a profit of $40 million, or 15 cents a share, versus a year-ago loss of $111 million, or 52 cents a share. The latest quarter included a net special gain of $6 million, while the same period last year included $36 million in after-tax charges.

Excluding one-time items, including legal settlements, adjusted per-share earnings fell to 13 cents from 26 cents but beat Wall Street expectations for 11 cents.

Sales ticked 0.2% higher to $3.95 billion, beating estimates for $3.88 billion.

Gross margin widened to 14.6% from 13.4%, while overhead expenses declined 14%.

Supervalu continued to stem declines in retail food sales, which fell 1.1% to $1.07 billion. Save-A-Lot sales, which have also struggled of late, slid just 0.1% to $972 million.

Same-store sales were down 0.9% for retail foods and 0.3% at Save-A-Lot.

The slimmed-down company, which sold five grocery-chain brands in March, has said it will cut 1,100 positions from its corporate and support-center offices.

Supervalu has also cautioned that it will focus on lowering prices and improving its fresh meat and produce departments, all of which may pressure margins.

Shares were down a penny at $8.39 Thursday morning. As of Wednesday’s close, the stock had soared 240% on the year.

Follow Matthew Rocco on Twitter @MatthewRocco