We went through a lot of this when ds was 3 or so, and still go through it some. Our main solution was to implement "sleep rules" whereby my son has to stay in bed all night, and if he gets up too much or doesn't go to sleep on his own, he doesn't get a treat. If he stays in bed all night, from when we put him down til morning, he gets a treat. (Otherwise, we're failry strict on treats.) It took awhile, and we still have relapses, but it has been a great improvement!