The secret is lots of praise and treats when he poops outside but when you catch him in the act doing it inside, scold him (but don't beat hime) and then put him in his kennel for a while. He'll soon learn that pooping outside is fun but doing it inside is bad.
Also thoroughly disinfect the area where he's been doing his business.
Use something like this...