It sounds like he just hasn't learned to go outside only - the problem if you punish him, even if its just telling him off or showing him a mess and telling him he is bad is er, several-fold..
Firstly - he won't link his actions to the actual problem, that the poo/wee is in the wrong place.
Secondly - he WILL associate the presence of poo/wee and YOU with unpleasantness
The chances are then that if you come home, or you come downstairs and he has messed, and you find it and tell him off.. it makes him more anxious, because he doesn't understand... the more anxious he gets the more likely he is to mess, particularly when you go out. Its actually a classic way to create or worsen a seperation anxiety problem.
As has been said - treat him like a tiny puppy - out as often as you can, reward superwell when he goes outside, really throw a party for him so he knows you LOVE it when he does it there. Try once he gets the idea, to associate a cue word with the action (just say 'weewees' or 'toilet' or 'busy' as he goes, and repeat that word each time he goes until its associated with the action).
If he has an accident.. well its your fault really, for not preventing it.. so clean it up when he isn't present (because no matter how good an actress you are, you will behave in a way that makes it clear you are unhappy and a sensitive dog will pick up on that) and say no more about it.
Personally, at night if he is doing this, I would move him into my room - start out crated and then move him into his own bed, t hat way IF he gets up in the night you can hear him and take him outside. Once he can handle keeping clean overnight in a room you are in you can then move him out of that room to the landing for example (you may need to return to crating to keep him in one place).. and so on until he is more confident and happy.
Sometimes very small changes can really fix a problem, I remember one lady whose dog suddenly started weeing when left, even if she was upstairs. She was pregnant and her bitch picked up on this... it actually turned out the WHOLE problem was caused by her putting a baby gate at the bottom of the stairs so the bitch could not come upstairs any more. She moved the gate to her bedroom door so the dog could see in, but not actually COME in.. and end of problem. The dog was just anxious because from her point of view, she couldn't see her mum/get to her at night.