According to Behavioral Analysis the first respondent is correct, but I would add another couple of steps to the mix. First every child, even two year olds, need to be given a set of expectations, so a couple of hours on and off before leaving the house you could make it a routine to talk with your two year old about what behaviors are expected when you leave the house. You could focus on safety (i.e. holding hands when you cross the road), using an inside voice when in the store, sharing toys when with a friend, etc. These little scenarios give you a basis for what behaviors to look for and reward with a quick word of praise. Then if he does happen to say the bad word, allow yourself to be only a little bit embarrassed, but know that you are working on long term behaviors and focus on that (years down the road you will have a humorous embarrassing story to share). So, ignore the bad word and give praise when does things that you DO like. The trick is not to give praise every five minutes or anything like that, but to give reinforcements for behaviors you desire - rather than reinforcing (which can be ANY attention) to things that you don't. As long as you are consistent, this process works with just about everything and every age group! It may take a couple of days to work, but perhaps those days you can just hunker down in the house! Another idea is to incorporate his older sister into the ignoring the word too. She is old enough to understand the concept that he may just be doing it because he likes the attention. Perhaps when her brother goes for a couple hours without saying the bad word, his sister can initiate a fun activity with him as a subconscious reward! This also provides your daughter with skills which she can use in her future life too!
Good luck and I too would love to know how you decided to handle it and the about the outcome! There is more than one way to "skin a cat" and I'm never to old to learn a new trick!