I had this problem with my small pets and my toddlers but they quickly learned what was tolerated and what was not. They got timeouts...instantly, every time. I wouldn't let them touch a hot stove and I sure as heck was not going to sit by while they tormented my aging senior small pets!
You could try pet gates when you cannot supervise. Make sure the dog realizes she isn't being penalized. Again, any inappropriate behavior gets an instant time out and/or take away the toy.
Explain to your child why he can't do it. Tell him it hurts the dog. Show him if he hits a stuffed toy, it doesn't hurt...(just a thought) but it does hurt the doggy and we love the doggy and just like mommy doesn't hit you or you don't hit mommy, we also don't hit the dog. Tell him it makes the doggy sad and doggy deserves to be happy too.
My kids ended up being great with pets at a very young age. I will tell you that if one of my pets 'snapped' at my kid, well, I explained that is the pets way of telling him to stop; that pet doesn't like it.
Get those pet gates up too. Does pet like toys? Maybe involve son in supervised play time with pet too.
I'm glad to hear you want to stop it. A lot of parents ignore it and just think the kid should have the run of the house when it comes to the pet. Teaching them to care teaches them 'empathy' and understanding when an animal sad or happy.