Mustahab and Makrooh actions

Teaching in the Musjid

Q: Can an ustaaz teaching with a salary teach in the musjid so that he may sit for the sunnat I'tikaaf in Ramadhaanul Mubarak? If not, could he continue with his teaching in the masjid and proportionately give back his salary?