It may be helpful to know that most young children will use "bad words" at some point, if only because they've heard other people say them and they want to see your reaction. This is typical of preschoolers and it's also likely to happen again when they start school or day care.
Your child will learn what's okay and what isn't either from the way adults respond to his language or from the language adults use themselves. As your child gets older and learns to master language, he won't need to use swear words to express negative feelings.
It's important not to seem too upset when your child starts swearing. Your child may not even know what the words mean. But it's also important not to ignore it, either. She may be swearing as a way to get your attention. So instead of getting upset, clearly and calmly explain, "We don't say those things in our house." And make sure you live up to your word by not swearing as well.
It's also helpful to encourage your child to talk about his feelings. You can help by suggesting acceptable words to use when he is angry or frustrated.
There are children who will continue to swear or call people names even after they know it's unacceptable. They may do so because they're constantly exposed to such language in their family or neighbourhood. They may also be unusually aggressive or defiant children. Or perhaps they're behind in their language development, so that they don't know how else to express their anger and frustration.
If this behaviour happens so often that it's clearly causing problems for your child, consult your child's physician. If you are in Canada, and you wish to speak to a counsellor about this, contact Parent Help Line, 1-888-603-9100.