With the limitation of a certain amount of spots to place units to build I was wondering how after the player researches upgradeA BuildingA is removed and replaced with BuildingB
You could try using the "replace unit" trigger action, you could also try using the chaos ability (the siege engine uses it to morph into it's anti-air version when the barrage upgrade is researched).