Question: If I daven maariv after nacht, should I wait to count the omer or count as soon as it is nacht?
Answer: The Shulchan Aruch Harav (OC 489:3) writes that while one can count the omer any time during the night, lechatchila, one should count as soon as it is nacht. Therefore, the Mishna Berura (589:2) writes that it is common practice to count the omer before saying aleinu so as to utilise every opportunity to count the omer as early as possible.
The Magen Avraham (489:7) and Shulchan Aruch Harav (OC 489:16) write that one may count before maariv even on Motzaei Shabbos when one extends Shabbos into the night. Nonetheless, it is preferable to daven maariv first, following the rule of tadir ve’sheino tadir, tadir kodam, the mitzva that we do most often takes precedence. As the mitzva of sefiras haomer is less frequent than kerias shema, one should recite the shema first.
The Mishna Berura (Biur Halacha 489:1) gives two reasons for why the omer was counted later. He quotes the Chok Yaakov (489:16) who gives the argument of tadir, and quotes R’ Yaakov Emden (Mor Uketzia 489) who explains that historically, people davened maariv before nacht which is why they waited to count. R’ Moshe Feinstein (Igros Moshe OC 4:99:1) challenges this reason, as one would always daven maariv first, regardless as to what time they were davening.
R’ Menashe Klein (Mishne Halachos 8:193) adds that most poskim maintain that counting the omer nowadays is miderabanan while reciting the shema is mideoraisa. As shema is said within maariv with two berachos before and after, one should daven maariv first.
R’ Yitzchak Yaakov Weiss (Minchas Yitzchak 9:56:2) writes that while the rule of tadir may not apply to one waiting to daven, both the Shela and R’ Yaakov Emden write that it is ideal to count with a minyan, so it is best to wait to count.
R’ Shmuel Wosner (Shevet Halevi 6:53) argues that while it may actually be best to count at nacht, people who count together in shul are more likely to remember to count.
In conclusion, one should wait to count the omer in shul at the end of maariv.