It likely depends on whether the speech in question is germane to the subject matter and advances a legitimate educational objective. If the speech is totally unrelated to the subject matter, then an academic freedom claim will fail. On the other hand, if the speech relates to a valid educational objective and is related to the subject matter, the professor could make a defense based on academic freedom.
It also depends on the university’s policy with regard to sexual harassment. For instance, one federal appeals court ruled in 1996 that a university could not discipline a professor who used vulgar language and talked about sexual topics in his English class because the university’s policy was too vague and had never been applied to the professor’s controversial teaching style. The court wrote in Cohen v. San Bernardino Valley College that “the Policy is simply too vague … in this case.” The court noted later in its analysis that “the legal issues raised in this case are not readily discernible and the appropriate conclusion is not so clear.”
Other relevant factors would be: the frequency and severity of the sexual comments; whether the comments targeted specific individuals or were of a more general nature; whether the professor had notice that his or her teaching methods crossed the line; and whether prior complaints had been filed and were made known to the professor.