I am trying to write an essay and the only phrase I can think of is "shit happens". I'm wondering; is there any formal way to say shit happens?
I think the closest expression with the same meaning and very similar connotations would be the French expression:
C'est la vie.
You can use the French phrase as is because it is famous enough to be understood in any English speaking country.
Certainly there are some more possibilities to say it in a polite way as to avoid vulgarity:
or you can use the English idiom:
Worse things happen at sea.
as a way of telling someone not to worry so much about their problems.
Lucian's suggestion of "C'est la vie" is a good one. There are a few other ways you could express the same idea:
Depending on the context, you might want to reference Murphy's Law. Murphy's Law is often stated as:
Anything that can go wrong, will.
This is a phrase you would use if you were talking about things going wrong before they did, or how they could have been avoided.
If you're talking about something going wrong after the fact, and especially something that could not have been prevented, you could also say:
This is a more idiomatic way of phrasing Pazzo's suggestion. The implication is the same: in life, things happen, good and bad, and you just have to deal with it.
For a more literary tone, you could use the Burns quote suggested by TRomano's comment, the actual original phrasing of which is:
The best-laid schemes o' mice an' men
Gang aft agley
This is often misquoted in more standard English as:
The best-laid plans of mice and men
Oft go awry.
To avoid the expletive, you could just say "stuff happens", which is somewhat idiomatic (though not nearly so idiomatic as "shit happens").
That's still rather informal but, in the right context and used only occasionally, informality can work well in an essay. It lightens the mood. Be careful not to over-use informality and be careful that it's only a little break from the serious stuff and that it doesn't ruin the flow.