As you already know, the First Amendment to the U.S. Constitution protects free speech. Because of the Amendment, police officers generally cannot arrest people, nor can the government prosecute them, simply for what they've said.
There are, of course, exceptions to the prohibition against punishing speech. Statutes that outlaw speech that's likely to incite violence constitute an example. But officers can't use laws of this ilk simply to punish people who mouth off to them, even those who use profanity. (Hartman v. Moore, 547 U.S. 250 (2006), City of Houston v. Hill, 482 U.S. 451 (1987).)
Example: Officer Hauk responds to a report of someone selling cocaine on the street corner. He encounters and confronts Bodie, who matches the description of the seller. Bodie yells and swears at Hauk. He attracts a crowd of onlookers. He then encourages the crowd to join in his protest of Officer Hauk, screaming that this situation is similar to the LA Riots. Officer Hauk is justified in arresting Bodie for disorderly conduct because the latter's actions were likely to cause violence. (Chemalali v. D.C., 655 A.2d 1226 (D.C. 1995).)
Example: Hauk, stationed in the subway, sees Bodie jump the turnstile. He stops him and issues him a ticket for not paying. Bodie yells and curses at Hauk. A crowd gathers, and Bodie continues to curse. Hauk arrests Bodie for disorderly conduct, but the reviewing court finds the arrest illegal because there wasn't evidence to suggest that Bodie intended to incite the crowd; he didn't interact with it, nor did it become agitated. (Shepherd v. D.C., 929 A.2d 417 (D.C. 2007).)
As these examples show, the line between protected and unprotected speech can be thin. Those who, knowing the First Amendment's protections, are tempted to antagonize police officers should think twice. Not only may the speech actually violate the law (a resisting arrest charge is among the possibilities), but an offended officer might misrepresent what the speaker said or find some technical violation to justify an arrest. (For example, an insulted officer might arrest a bar hopper for being drunk in public.)
If you've been arrested after a confrontation with a police officer, consult a knowledgeable criminal defense attorney. That lawyer can advise you of the applicable law and your options.