RAW: Yes, that would work!
- You can wield a two-handed weapon in addition to a shield.
Two-Handed. This weapon requires two hands when you attack with it
(PHB p.147, emphasis mine)
So you can wield a two-handed weapon correctly, but cannot attack with it, if your other hand is occupied.
Shields. A shield [...] is carried in one hand.
(PHB p.133, emphasis mine)
So, you can carry the shield in one hand, while holding your weapon in the other hand.
- The opportunity attack would be triggered
By your definition, you are wielding a weapon specified in the Polearm Master feat. So you would get the opportunity attack, which you cannot perform (due to the shield), but replace by a spell (due to War Caster).
- You could cast eldritch blast
You can cast a spell as an OA using the War Caster feat, you have to fulfill the components of the spell. For Eldritch Blast those are verbal (no problem) and somatic, which "you can perform even when you have weapons or a shield in one or both hands" (PHB, p.170, War Caster feat). You would also have to target all individual beams at the creature, which triggered the AoO!
So, all conditions required for this technique are met, but as you said, you wouldn't be able to use your two-handed weapon!
Unless your two-handed weapon gives you a relevant bonus I would suggest using a Quarterstaff or a magical staff you might find as your weapon; they fulfill the requirements of Polearm Master and you would be able to use them one-handed because Staffs are (unless stated otherwise) quarterstaffs. (DMG, p.140)