All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Making up for the missed prayer should be done immediately when one recalls it. In addition, making up should be in the same order as the prayers themselves; i.e. if one forgets the prayer of Thuhr or sleeps through its time and recalls it after the ‘Asr time has started, then he/she has to perform the Thuhr prayer first, and then 'Asr.
The Prophet said: “Pray (in the same manner) as you see me praying.” [Al-Bukhari]
Another Hadeeth reported by Imams Al-Bukhari and Muslim reads that the Prophet was engaged in Jihad on the Day of the Confederates (al-Ahzab Battle) and then he performed all prayers in their original order after sunset. This means that following the above-explained order is obligatory.
Thus, if a person cannot perform the Maghrib prayer before 'Isha, he can follow the Imam who is going to lead the 'Isha prayer, with the intention of the Maghrib, and when he completes the 3rd Raka'h, he has to remain in his sitting position until the Imam completes the 4th Raka'h and then sits, and finally, he follows the Imam when the latter ends the prayer with Salaam.
But, if there is not time enough except to perform the 'Isha prayer, then you can perform 'Isha since delaying 'Isha from its fixed time is not permitted.
By the way, making up for the missed obligatory prayers should be given precedence over the Witr prayer. Furthermore, know that the Witr prayer becomes invalid if you perform it before 'Isha.
In addition, some scholars believe that if one performs 'Isha prayer with the Maghrib prayer due to some genuine reason at the time of the Maghrib prayer, then performing Witr will not be valid at such a time.
Allah knows best.