Start by thinking constructively. Well, take a little time to vent a bit and let some steam out, but then get constructive. What is under your control here? I'd say your job is, so think about doing something you enjoy professionally and getting around people who have good energy.
You are on a running message board, so you are probably a runner. Use that - it is a great stress release.
Work with your soon-to-be ex, not against her. There are always two sides to every story, so try to genuinely understand hers or that she probably has one. Okay, you two aren't compatible, and it is time to go your separate ways, but you cared for each other at some point, and it is unlikely she is pure evil. And you have a mutual interest in your kid.
Now to the kid. Every 12-year-old gets defiant. It would be strange if he was not. But, why is he this way? Is something deeper going on? What can you do differently? My son and I were at odds all the time when he was in middle and early high school. One day, I convinced him to go on a walk with me, and, almost sobbing, I told him that I was unhappy that we weren't getting along and that there was nothing more important in my life than him. I asked him to consider that when I disagreed with him it was because I am older and I know some things. It is fine to push back, as that is natural, but don't ever think for a moment that we aren't on the same team and that I don't care. I told him I would mess up a lot, but to never assumed I didn't care. Not to elongate this, but that kid is now almost 30 and he tells me that conversation turned his opinion of me, and I am proud of what he has become.
Let some of the little things go, for sure. Choosing your battles is important. Get through the stages of grief. Maybe do one of those online things like Better Help if you need a stranger to talk to.
But don't give up. I can guarantee you that kid is not going to be at 16 what he is at 12, and you might be surprised at what he becomes. You need to be a part of it.