the complexity depends on the spells themselves. For example you can change the missile model path via triggers (not sure at the moment if it works or not), but you cannot change icon.
So if you want to change spell icons as well when changing mastery, then I don't think you have any other choice but to create a copy of the spell with different icon (and other stuff like buffs, etc.).
Of course, here I assume that the spells are same, but just some visuals change. If those are completely different spells, then that won't help here.
Detect when unit changes mastery via triggers and just remove the old mastery spells and give the unit the new mastery ones.
If those abilities are hero abilities, then removing them via triggers may not work. What you can do instead is give the hero all mastery abilities in object editor and in triggers at map initialization disable all hero's abilities except for his current mastery.
Detect when hero learns an ability and via triggers add additional skill points to hero and force the hero to spend them on the same abilities but from the remaining (disabled) masteries.
And finally, when hero casts mastery change, you just disable spells from current mastery and enable the next group of spells