Keep your dog on a feeding schedule. This will help you to know when he needs to relieve himself. Remember that your puppy cannot truly control himself until he is about five months old. Clean any accidents with a product that will remove the entire odor. Do not use ammonia or products with ammonia in them.
Ammonia imitates the smell of dog urine.
Use a crate when you cannot supervise your dog. If you do not want to crate your dog, use baby gates to keep him in a safe, enclosed area. Hitting your dog won't teach him the difference between 'going inside' and 'going outside'. Rub your dog's face in his waste. Not only it is dirty, but will likely make your dog neurotic and afraid of you.