We got some great advice on this one when my son was in preschool. His teacher, who is also a therapist, said to take the power away from it by calling them "bathroom words." The kids can only say them in the bahroom.
Explain it to them as the new rule at a time when it's not happening, then quietly, and without anger, remind them when they start that those are bathroom words and if they want to talk like that, they need to go into the bathroom.
Words only have the power we give them. By choosing our battles, we save the power struggles for times when they're really needed. This age is short...enjoy the giggles you hear coming from the bathroom, and don't worry about it too much!
As for the tantrums, consistent, calm and quiet are the key words. Recognize his anger, feed it back to him with things like "Wow, you look like you're feeling angry." Make soothing sounds to him, and when he's done say things like "I bet that was hard. I don't like feeling so mad. Do you?" Teach him to express his feelings. Ask him if he got all the angries out or if he needs to stomp and wiggle some more. Do it together. You will probably wind up laughing together. Just MAKE SURE you don't ever tell him not to feel what he's feeling. It's so important that we don't ask our kids to hide their feelings or stop feeling them. It sets them up for a lifetime of being out of touch with themselves, stuffing things down...not good! Especially with our boys. They learn early on that they shouldn't feel, and this leads to all kinds of problems later on. The feelings aren't wrong. He just needs to learn healthy ways of expressing them. This is a process that takes a lot of patience on our part, but is so important.
Good luck!