May One Live Above a Shul?

The Shulhan Aruch (Orah Haim 151:12) says that if there is a floor above a synagogue, one should be careful not to use it for unbecoming activities such as laying down. This is based on the Mordechi (Shabbat, ch. 1), who says that the holiness of the Bet HaMikdash extended upwards, and since a synagogue is a considered a miniature Bet HaMikdash, it would apply there as well. Nevertheless, Rabbi Yosef ben Oualid (Shu”t Samo Yosef 53b) writes that the Rambam wrote a responsum permitting living above a synagogue. Although his city of Tetouan, Morocco followed the opinion the Rambam, Rabbi Yosef ben Oualid himself agrees with the Shulhan Aruch’s approach. Furthermore, Rabbi David Kohen-Skali (Kiryat Hana David, vol. 1, § 29) says that there should be no living quarters above a synagogue. Interestingly, the Taz and Rabbi Haim Benvenisti (Knesset HaGedola) both attribute personal tragedies to leniencies regarding living above a synagogue. Nowadays it appears that the prevalent custom is to be lenient and to permit living quarters above a synagogue. However, all opinions agree that having a restroom where all sorts of bodily functions occur would not be allowed over the sanctuary.
Summary: One may live above a synagogue but one may not have a bathroom above the sanctuary.