I used to have trouble sleeping as the problem of the day was constantly in my head. My minimal solution is to go home at a milestone point where you've solved the problem to a point requiring further debug/writing of code. I try to apply this always now, especially for weekends and vacations.