Psychologically it's been found that swearing helps alleviate stress and pain, so I can easily see how profanity could date back to ancient times.
In "Holy Sh*t: A Brief History of Swearing" the author postulates that swearing dates back to the time of the cavemen.
Go ahead and listen to the audiobook excerpt from that Amazon link, it talks about swearing in Roman times which corresponds perfectly to Spartacus. Swearing during the late medieval period (Game of Thrones) would also have been extremely common.
I can't resist a link to a favourite book:
Every culture and language that has ever existed has had profane words. The words themselves and their magnitude are programmed into us at a very early age. Not only are they loaded with emotional context, but they actually trigger a deep-seated neurological response on the part of both the speaker and the listener.
Even people who use profanity on a regular basis have interesting reactions to profane words. You can become somewhat accustomed to them, but they will always hold a slightly different status and weight in your mind. There is something that sets them apart.
What's really interesting to me is how the words that are and are not profane change over time. The Romans for example, were a lot like us. The bad words to them were mostly about sex and bodily functions, although the way they ranked them from most severe to less severe were pretty bizarre by our standards.
In the Middle Ages, people used vulgar terms for shitting and fucking and lots of other acts, but no one really considered them offensive. In fact, some of the earliest translations of the Bible contain words that would shock you, because the people doing the translating simply didn't think of them as bad. In the Middle Ages, all the really offensive terms were religious. Saying "By God's bones!" was every bit as shocking and offensive to them as screaming "Cunt!" in the middle of a church service would be to you and me.
And the list is still changing today. Your great-grandmother probably couldn't say "Damn" or "Ass" without blushing, but she could say "Nigger" without thinking twice. You probably cannot. For the first time in history, many racial slurs are beginning to have the kind of psychological impact that other profane terms have.
There's been some fascinating research on this topic. If you're interested, I'd recommend checking out a book called <em>Holy Shit! A Brief History of Swearing</em> by Melissa Mohr.