I can relate to this so much. I tend to just act out rashly, not thinking about what to say before i say it, which just gets me into more trouble. While this is a very hard thing to deal with, the first step is to breath. Take a deep breath and clear your mind. In whatever situation you're in, patience and equanimity is key. Then think about what the person just said that would essentially lead you to lose control and view the situation from a different perspective. "Do I really need to respond in a negative way?" "Is this argument even necessary?"
ask yourselves these questions. You may find that just walking away will solve the problem, giving you some time to think and then coming back when you're ready to talk in a rational and calm way. Or you may not even nee to go back if the comment of the other person is pointless and plain stupid.
I hope this helps:)