I am sorry you are going through this, I know it must be tough. Some of the advice is excellent here, but not all of it. Stick to your guns. Just because the lessons you teach aren't consistent everywhere he goes, doesn't mean there isn't a lesson to be learned. This could be a lesson in respect of other people's rules outside his home. No, you may not change him, but at least he will soon see that it's your house...your rules.
Give it up with the ex-wife. Sounds like she isn't going to help you one bit. She doesn't see that she is spoiling this child, and unfortunately, you won't be able to help her see that.
All kids go through a hate stage or 2. Mine have already been through one, and I am waiting for the teenage years to go through it again. We have had a rule in our house for a few years: WE DO NOT HATE IN THIS HOUSE! They can say what they want to about me, but if I were to catch them talking like that about me, or calling me a *B*, then I would let their father deal with it. My husband is pretty strict when it comes to the kids disrespecting me.
It sounds to me like your husband may need to be a bit more involved in his son's life. Visitation isn't for the kid to go somewhere else and get out of one parent's hair, it's so the other parent can spend time with their kids.