About detecting upgrades:The easy way is to simply make the upgrade cost N minerals, and detect when you used them (obviously for the upgrade).
The hard way is by EUD, but I don't know much about them so I won't tell you. Maybe it's even impossible with EUD
About Changing WeaponsIt's a usual bug: if you try to replace a smaller unit with a bigger unit and the bigger unit does not fit because of terrain, it can(the bigger unit):
-Not move
-Get moved to the center of the map
That is, if you move it from a remote location.