This is part of having a dog, and if you want it fixed you need to commit yourself for the next little while. Your dog has been getting mixed messages and has no idea that peeing in the house is bad, and doesn't why sometimes you get angry.. He cannot train himself, especially when he has no idea what he is doing wrong and what he is supposed to be doing..
You need to keep eyes on the dog at all times when in the house, attach a leash to you and to the dog. If you cannot have the dog with you, put him in the kennel. Take him outside at regular times, after eating and drinking after play and after naps. When he goes outside have a party. If you catch him squatting in the house clap your hands and say no, go outside and praise when he goes. Every time the dog has gone in the house without someone seeing it has reinforced it, if it happens again it will take you 2 steps back.
Please don't punish your dog that way. He had no idea what he was doing was wrong. That and it will also not fix anything, that 'training' doesn't work. It will only make him lose trust in you, and it will make him pee in the house more.
You need to be positive and consistent, If you are not consistent and there is an accident than the only one you can blame is yourself. I know it can be a long and frustrating process, but patience and hard work will pay off. There is no such thing as a dog that cannot be trained to go outside so there is a light at the end of the tunnel I promise!