Have you taken him to the vet? You'd first want to get an all-clear that this is not related to a medical problem.
If it isn't medical: then it is first and foremost, a housetraining problem as this indicates he isn't actually fully housetrained. I'd recommend starting *from scratch* -- taking the same approach you would with a puppy. No shortcuts!
You can get excellent housetraining advice and directions here:
http://www.dogstardaily.com/files/Housetraining_0.pdf
An adult, healthy dog should never need to eliminate during the night -- but to help remove any potential reasons to go, I'd switch to feeding in the morning, or if feeding twice daily, the second meal at 5pm or so but not much later so he digests and empties his bowels *before* bedtime. Give him at LEAST a 30 minute walk before bedtime so that he does a poop then and he will not need to go overnight. Give NO food, *no treats* in particular, after 5 or 6 pm. Do not give access to water after about 9pm.
So your approach needs to be:
1) medical: make sure this isn't the cause or no amount of management/training will help
2) management: most dog behaviour concerns are really just as much an issue of thoughtful owner management as they are of training -- and often, management alone eliminates the problem, which is much easier than training! You can set him up for nightly success by not feeding in evenings, giving him plenty of exercise nightly before bedtime, and managing where he sleeps so that he isn't going somewhere he shouldn't be (eg not on carpet or rugs). Crating a dog (crate train FIRST though!) generally removes nighttime accidents, for example.
3) training. At the moment you don't have a housetrained dog (assuming the problem isn't medical) so start from the very beginning as you would with a puppy or rescue adult dog and go from there, using the training sheet linked above.
That should solve your problem within days or a couple of weeks.