This is a very good question and relevant to current events. There is some debate on what would happen with a heretic pope. I think the majority opinion is that a pope who professes formal heresy ceases by that act to be pope automatically. There is both scriptural precedent and precedent in Church history for bishops and others in the church hierarchy rebuking the pope for wrong teaching. You might find this article on the dubia helpful, it touches on your question.
Usually, you wouldn't lose your office for misconduct as pope (though the pope can punish anyone else for misconduct), but you could definitely be rebuked. There's plenty of precedent for that. If Cardinal Burke is correct, and I believe he is, a Pope preaching formal heresy would immediately cease to be pope, however, and could and should be replaced by the college of cardinals once he has done so.