I’ve had unrelated comments from others that it is because I’m direct and opinionated, and not afraid to defend my opinion.
This is a part of it, but people who are misogynistic will just be misogynistic. They have problems with your existence, and no amount of sugar coating or changing your wording will subvert this.
The most tangible advice I can give to you right now is the following - your boss is clearly an ally. He not only recognized the bad behavior, but was willing to let you know about it. This is frankly rather rare, and you need to find individuals like this and pay attention to them. Come to them for advice, because they are the insiders who know how to work the system, are listened to by the system, and will be willing to work the system to balance out the forces which are currently acting against you.
I have all kinds of self- deprecating behaviors
Don't use these in the work place. Challenging your own credibility in public where these people can see it will result in them using this as ammunition when arguing as to why they don't like your opinions, thoughts, suggestions, etc. You need to be direct, come off as competent, and know when to disengage. That way if any outsiders get pulled into the situation, your actions can speak for themselves.
On another note I would suggest looking around for female leaders at your company or people which you can count on who are higher up than you. Become their friends and ask them for advice. They've likely got a better lay of the land politically than you do because of their position, and they'll know where the problematic individuals are or how to get around them in a way that won't come back to bite you.
If there are employee resource groups or professional women's groups of any sort at your company or even in the field that you work in, go sign up and look to them for mentoring and advice as well. These resources can be extremely beneficial in the long term and can help you learn more strategies to deal with discrimination in the workplace.
Finally, be wary of HR - they care about your company's health more than anything and if you come to them with sexism their job is to protect the company from you being able to sue them over this before it is their job to help you with navigating this issue of interpersonal relationships. Often times many people who work in HR are female, but that does not mean that they will protect you if push comes to shove. In some companies they may, but there's a conflict of interest with people who roll up into HR so in general you should always be wary of coming to them with anything.