Mine are a similar age and it's so hard because I hate that people think I 'let' them get away with swearing like sailors and calling me stupid. It's super embarrassing, especially in public. I can talk a big game to others, but deep down it does feel mortifying for me to have my child speak to me like that. I'm a big girl now, and I can bluff my way through the embarrassment for the sake of giving my kids the reaction they actually need me to give them, but my feelings don't change even if my outward actions say another thing.
That being said, I've found that whatever I do react to tends to become embedded. So I try not to react too much, or if I do be as playful as possible. Sincere conversations about hurting feelings don't work for my two because they are just not at that stage where they can tolerate the idea that I'm a human who can actually be hurt. They need me to be invincible so they feel safe, and I try to give them that as much as possible for the moment. I try to respond with humour, with a song, or by every time they say the word making a raspberry when they are about to say it and then acting really surprised when they try to say it and I blow another raspberry. I then usually divert their attention to a fart joke and because that age group loves a fart joke, we reduce the tension and it goes away. Later on they might say sorry they might not, but I try to connect. I try to model saying sorry to them as much as I can and it does work.
We do also explain on repeat that whilst they might have cross words in their head and hearts, and mummy and mama will always love them no matter what they say, other children will not want to be friends with them if they call them names and are rude.
Sometimes if it is really bad, we go down the 'sugar and sweets can sometimes make children overexcited and swear. Maybe you don't need any haribo.' route. this works best if you have a regular daily treat that is unconditional on everything else. So we have what we call toilet treats that we used to use as a reward for using the toilet, but now we have repurposed into being for if they have gone the whole evening without hitting anyone. They have 2, and lose one each time they hit. Most days now they get both sweets and then it fades away until we work out what the next behaviour is we want remedied. The name toilet treats still remains though!
Not quite the same, but mine also went through a phase of dropping the f bomb like it was going out of fashion. I began to say 'look, I don't care what you say, but you must not understand any circumstances, say the word flipping. There will be serious consequences if you say the word flipping.' and so far that works quite well. I regularly hear 'shut your flipping mouth', which isn't nice, but the alternative is much more jarring! The key to adjusting behaviour is to work out what baby steps you can take towards reducing it. So maybe going from insulting you to not insulting you might be a big shift, but if you could move to them saying something marginally less emotive, that's a step and a improvement. As is getting them to adjust the tone of voice, location, or method of saying it.
I also find that removing myself from the situation helps. I may not be able to control them, but I certainly don't have to sit there and listen if all that are going to do is saythings that are designed to upset me. So I try to remove their audience and go and do something somewhere else, which stops me getting mad and emotional, particularly if that something else is filling my face with maltesers from the fridge door whilst pretending to look for broccoli.
One of my friends has the idea of toilet words that can only be said in the toilet, which I thought was novel. So it takes the power out of the mean words by permitting it within certain parameters.
However, as others have said, the reasoning behind it is good to try and work out. Swearing when hurt is shown to increase pain tolerance, and I often wonder if them lashing out is a way of them reducing their own pain. It's them trying to hurt you and make you feel just how bad they feel because their world is too much to bear at that moment for whatever reason. So sometimes I change my tack from humour to soothing, because it must genuinely feel horrible to have all of that build up in their little bodies. Mini releases throughout the day can help, as people have mentioned above, or recognising any patterns - is it always if they are hungry or being interrupted at play? Etc.