How can I avoid inadvertently offending my female peers and getting into trouble for it? Attention has been drawn recently to an incident that occurred at a scientific conference and its sequelae described in this article:

The fuss started when [Prof. X] and [Prof. Y] ended up in the same crowded elevator during a conference at a Hilton in San Francisco last month. [Prof. Y] said she offered to press the floor buttons for people in the elevator, whom she described as mostly conference attendees and all, except one other woman, white middle-aged men. Instead of saying a floor, [Prof. X] smiled and asked for the women’s lingerie department &quot;and all his buddies laughed,&quot; [Prof. Y] wrote in a complaint, the details of which [Prof. X] disputed.
[Prof. Y] [...] then wrote to the association’s executive director, who forwarded the complaint to the group’s Committee on Professional Rights and Responsibilities, which determined that [Prof. X] had violated the conduct code.
[Prof. X] insists it never should have gotten to that point because he tried to resolve the problem informally, as the association’s conduct code recommends. After being informed that his conduct was under investigation, [Prof. X] wrote [Prof. Y] an email assuring her that &quot;I certainly had no desire to insult women or to make you feel uncomfortable.&quot; He suggested that [Prof. Y], who was born in Romania and raised in Israel, might have misinterpreted his remark. When he was young, in the 1950s, he said, it was a &quot;standard gag line&quot; to ask the elevator operator for the hardware or lingerie floor as though one were in a department store.
&quot;Like you, I am strongly opposed to the exploitation, coercion, or humiliation of women,&quot; [Prof. X] wrote. &quot;As such evils continue, it seems to me to make sense to direct our attention to real offenses, not those that are imagined or marginal. By making a complaint to ISA that I consider frivolous — and I expect, will be judged this way by the ethics committee — you may be directing time and effort away from the real offenses that trouble us both.&quot;
[Prof. X] was told to write an &quot;unequivocal apology&quot; to [Prof. Y] and submit a written copy by May 15 to the association’s executive committee. The apology should focus on [Prof. X's] actions, rather than [Prof. Y's] perceptions of them, it said, adding that if he failed to comply, the executive committee would consider appropriate sanctions.

As a male member of academe, I am worried.  I feel bewildered and fear that I might also offend someone some day.
How can I avoid committing an equivalent faux pas in an academic environment, such as an international conference?
When I step on someone's foot in a crowded subway, I apologize, even if I didn't do it on purpose. I don't refuse to say I'm sorry, I don't imply in a sarcastic way that the other person should have gotten their foot out of the way, I don't suggest that it cannot have hurt all that much, and I don't tell them they should relax, it's just a prank.

If you read the full story, you will see that Prof X's problems really started when he reached out to Prof Y to tell her she was wrong and had no right to complain, and even further refused to formally apologize when asked to. When you read the organization's reasoning, you see that they also consider that it is not so much the intent of the actions that matters, but rather the consequences and hurt they caused.

So I would suggest apologizing if someone tells you that your actions hurt them, instead of telling them that they had no right to feel hurt. Showing that you are a human being capable of empathy helps, usually. I have never witnessed an attempt at going down the second route that worked out well.