I always think 'but for the grace of god go I' when I read about parents having trouble with swearing, it's pure chance my children don't swear. There are lots of gentle ways to approach this, and these strategies will change as your son ages. You've already taken the first step, you've stopped swearing around him. Four letter words are just like longer ones, if he doesn't hear the word 'intransigence' he won't use it!
It's too late to go back and fix the initial reaction. However you first reacted, it is usually a strong response that encourages him to use the word again.
A good way to start controlling the behaviour is to use a re-direction phrase like, "that word is offensive, it's not a word you should use".
Another way to redirect is to say, "it sounds like you're very frustrated, but you should choose another word?" or, "did you just say [an innocuous word that sounds a bit like the word he's used]?".
You'll also need alternative words such as "gosh", "dang", "damn" or whatever other words you feel comfortable with him using and model them in stressful situations.
Remember why children swear, it's the same reasons we do. Research suggests swearing releases tension and has pain reduction tendencies. It has emotional connection benefits and helps us manage our feelings. If our feelings aren't expressed, they don't go away, they come out in other ways. So, we have to let our children express their anger. Are you likely to stop completely? I know I'm not, nothing expresses my feelings like a good old fastioned curse word and it's better than hitting something!
Maybe, as he gets older, it's a good idea to monitor and manage the swearing, rather than trying to stamp it out altogether. So, remind him that there's people it's okay to swear around, and places it doesn't matter, and those it's not. Try to curb his desire to swear in public and keep it as an 'at home' and 'between us' thing, Grandma may not approve!