The gemara learns from the pasuk of כי ממנו תאכל ואותו לא תכרות that if one has a Rebbi who is a proper Talmid Chacham and acts in a manner that befits a person of his stature, one should learn from him and not separate. Tosafos explains that there is no need to seek out another Rebbi (I am reminded of a story that Rav Nota Greenblatt Shlit"a once shared. He was learning by Rav Moshe and the Mashgiach in Tiferes Yerushalayim was pushing him to leave MTJ to go learn in Lakewood by Rav Aharon, which was what everyone serious in their learning would do. He explained that at the time Rav Moshe was recognized as a posek but Rav Aharon was THE Rosh Yeshiva. He turned back to the mashgiach and said - ווו איז עס געשריבן אַז הרב אהרן איז גרעסער ווי הרב משה - where is it written that Rav Aharon is greater than Rav Moshe? To which Rav Nota commented "he looked at me as if I just told him I was a nekeiva"). But if the Rebbi doesn't act properly, he should seek out a new Rebbi and not learn from this one.
Tosafos asks from Rav Meir who would go learn from Acher and answers that a Talmid Chacham may learn from an improper Rebbi, but if one is not a Talmid Chacham they may not. It is strange that Tosafos even asks the question because it is directly dealt with by the gemara in Chagiga 15a and the gemara says a Gadol may learn from an improper Rebbi, but a Kattan may not (The Gevuros Ari understands that the distinction of the gemara is between one who is over 13 and one who is under 13, which is clearly not the approach of Tosafos. Perhaps Rashi in Chagiga - גדול היודע ליזהר ממעשיו implies like the gevuros ari). It seems from the gemara and Tosafos that so long as the Talmid is a talmid chacham who is able to discern what to learn from and what not to learn from, he may continue to study from the Rebbi who is behaving improperly.
However, the Rambam and Shulchan Aruch Y.D. 246:8 writes - הרב שאינו הולך בדרך טובה אע"פ שחכם גדול הוא וכל העם צריכים לו, אין למדין ממנו עד שיחזור למוטב. The Shach asks why the Shulchan Aruch doesn't make the distinction of the gemara itself and say that a Talmid Chacham is permitted to learn from an improper Rebbi? The Shach answers we find that even some of the Talmidim found in the gemara had status of a "kattan" and were not allowed to learn from improper Rebbeim, therefore nowadays the Rambam and Shulchan Aruch are assuming that everyone would have the status of a kattan and not be allowed to learn from someone who isn't acting properly. The Gilyon Marsha adds that even a proper custom that is instituted by such a person should not be followed.
I heard recently that some poskim told the talmidim of a Talmid Chacham who committed a serious aveirah that they should disregard anything that they ever heard from him because he is not a בעל מסורה. I find this approach very difficult to accept. The only discussion we ever find in the poskim is whether one can continue to learn by this person after he had committed an aveira and goes in improper ways, however, anything that he said prior to that can be quoted. Elisha Ben Avuya is quoted in Avos 4:20 for something that he said before he went off the derech and by being quoted in Avos indicates that he was very much part of the chachmei ha'mesorah. He is also quoted in Moed Kattan 20a regarding keeping aveilus on a shemuah rechokah. Clearly, the earlier teachings of such a person cannot be disregarded. It is difficult to make a distinction between Elisha Ben Avuya where we can attribute an exact time to when he changed his ways, to another Talmid Chacham. Furthermore, the Shulchan Aruch says explicitly - עד שיחזור למוטב, meaning that once he does teshuva, one can continue to learn from him. Rabbeinu Yona in avos requires being דן לכף זכות and assuming that a Talmid Chacham who sinned would have done teshuva for his aveiros.