I would get the check engine light diagnosed first ,could also be a high pressure switch or compressor clutch switch, I doubt a bad spark plug is the problem,get the code that is throwing the engine light on first!
If this happens only when the ac is on then its in the ac system or wiring...