One way to get rid off the spikes is to use a diode that is in reverse bias with respect to your transformer secondary.
Do you really need a 220 V square wave or is 220 V sine wave ok?
Here is some suggestion off the top of my head:
If sine wave on secondary is ok, then you could use a filter on the 12V side to get rid off some harmonics before you send the signal through the transformer. However, since this could be impractical a better solution is to connect load neutral to the dc battery midpoint. (e.g node in between two 6 V batteries). This would eliminate the 3rd harmonic which is most significant and also 9, 15, 21 etc. (these are not very significant). Of course you could also use different PWM techniques to get rid off harmonics. If you want sinusiodal output you could use SPWM or MSPWM, however if you want to get rid off specific harmonics only I suggest that you use the harmonic elimination techniques. Having ess harmonics means that you would have less spikes in your secondary voltage
I don't know if this helps