Twinkies baked goods are displayed for sale at the Hostess Brands’ bakery in Denver, Colo.

NEW YORK — A bankruptcy judge Tuesday approved the sale of Twinkies to a pair of investment firms, one of which has said it hopes to have the cakes back on shelves by summer.

Hostess Brands Inc. is selling Twinkies, Ding Dongs, Ho Hos and other brands to Apollo Global Management and Metropoulos & Co. for $410 million. Evan Metropoulos, a principal of the latter firm, said in an interview that he wants to have the snack cakes back on shelves by June and that the brands could benefit from new flavors and other product extensions.

He also said that comedians Will Ferrell and Zach Galifianakis are at the top of his “wish list” for potential pitchmen. But he doesn’t plan on formally approaching anyone about marketing deals until after the sale closes in coming weeks.

Metropoulos, which owns Pabst beer, has already used Ferrell in its ads. Apollo’s investments include the fast-food chains Hardee’s and Carl’s Jr., which is known for indulgent burgers and splashy ads starring scantily clad women.

Judge Robert Drain of the U.S. Bankruptcy Court of the Southern District of New York also approved the sale of Wonder bread to Flowers Foods, which makes Tastykakes and other breads. Flowers, based in Thomasville, Ga., would also get Nature’s Pride, Butternut, Home Pride and Merita as part of the $360 million deal.

Hostess has said the Justice Department is reviewing that sale.

The sale of Beefsteak to Grupo Bimbo was also approved. Grupo Bimbo makes Entenmann’s cakes and Thomas’ English muffins and is paying $31.9 million for the regional bread brand.

A separate hearing is scheduled for April 9 to approve the sale of Drake’s cakes, which include Devil Dogs and Yodels. Hostess picked McKee Foods, the maker of Little Debbie snack cakes, as the buyer for those brands at $27.5 million.

Taken together, a Hostess spokesman said 29 of the bankrupt company’s 36 bakeries were sold as part of the transactions. It will be up to the new owners whether to hire back the thousands of workers who lost their jobs when the company went out of business.

Mark Semer, a spokesman for Metropoulos, said the firms would hire “the most qualified employees for each of our facilities, and this certainly includes many excellent, former Hostess workers.”

The bakers union for Hostess, which had previously objected to the sales, said in a statement that it shared the enthusiasm exhibited by the new owners to bring Hostess brands back to shelves quickly.

The Bakery, Confectionery, Tobacco Workers and Grain Millers International Union said it believed “our highly-motivated and skilled workforce will serve as indispensable partners in the seamless re-opening of factories.”

The Teamsters, which was the company’s largest union, appeared less optimistic.

“The liquidation and sale process has only insured that the brands may live on — none of the buyers have made any comments to employ former Hostess workers let alone honor the terms of conditions of their employment with Hostess — in fact they specifically stipulated that none of the obligations carry forward as part of their bids,” the Teamsters said.

Hostess closed its factories in late November following a strike by the union. The company had been struggling financially for years.