The talented but troubled actor volunteered to spend at least 40 days at an undisclosed residential program in Southern California, according to Downey lawyer Robert Waters.

“He’s committed now to a life of sobriety,” Waters told reporters outside his office. “I think he’s turned a corner. He’s made some amazing breakthroughs.”

Yesterday marked Downey’s first full day of freedom after an appeals court set him free on a technicality.

The trial judge, in sentencing Downey to three years of prison time for one felony and three misdemeanor drug convictions, failed to specify that those three minor counts should be served consecutively.

Under California law, a judge must specifically say the terms are consecutive. If not, those misdemeanor terms are considered concurrent.

That oversight meant Downey has already served his time, and he walked out of state prison after posting $5,000 bail Wednesday afternoon.

Downey immediately got himself a hamburger, and checked into rehab the next day, his lawyer said.

“He’s working on being out of prison and re-acclimating himself to society … and doing his recovery work,” Waters said.

The state attorney general now has 40 days to decide whether to appeal the ruling. If there’s no appeal, Downey will be placed on parole for between 13 and 16 months, Waters said.

Deputy Attorney General Jeffrey Kahan said he and his bosses will closely examine the opinion for at least two weeks before deciding on an appeal

“I’m disappointed,” Kahan said. “It was an appropriate sentence. The trial court intended the misdemeanors to run consecutively.”

Once Downey’s freedom is final and parole officers allow him to accept acting jobs again, he won’t have to wait long for studios to call.

“Off the hook – definitely, they’ll call,” said movie-industry analyst Robert Bucksbaum, president of ReelSource Inc. “Even with all his problems, he’s still one of the most marketable actors out there.”

The Oscar-nominated star of “Chaplin” and “Less Than Zero” was first busted for drugs in 1996 and has violated probation twice.