You are only responsible for your actions... this teacher is responsible for theirs.
You hint that it would be unfair of you to be held accountable for saying a mean thing, and in the same post complain that this teacher is doing the same. One of those do as I say not as I do things... those always drove me nuts as a kid and still do. So, if you want this teacher held accountable you need to accept in advance that you will be as well.
That said, talk to your parents, admit 100% what you've said, and what the teacher has said. Same goes if/when you speak to a counselor, principal, etc. If you lie, even by omission, about your actions then no one will believe you when you talk about the teacher's.
Talk to fellow students. See which are willing to come forward to talk, give your parents and anyone else you talk to those names. Don't drag in kids who don't want to be involved, that's likely to backfire. They could easily take the teacher's side, even if it's a lie, just to get out of the situation and get the teacher liking them... most especially to separate them from YOU, the troublemaker. So stick to the kids who have heard these things, and are WILLING to talk about it. Have those names ready for verification when you talk. And as others said, tape wouldn't hurt either.
In the meantime, as others said, keep up on your work and be on your best behavior so that it won't be seen as a retaliation type thing.