So you had a misfire, and bought a whole new engine? That's way overkill.
When the Service Engine Soon light flashes, that indicates a misfire. Misfires aren't caused by Spark only (Spark Plugs, Plug Wires, Coil Packs, ICM), it can also be fuel related. Scan the code and see which cylinder is misfiring, then try swapping injectors and see if the misfire follows.