Idleing issues can be because of a bad idle valve sensor A.K.A (IAVC) or (IVAC) (im not exactly sure but its attached to the airfilter box its black in color.
The issue can be resolved by cleaning the sensor at most you might need to replace the sensor.
The check engine light, if its on continusly once try removing the battery wires for a minute or 2. Reconnect and drive your car if it comes up again try getting your car scanned with a OBD device (car scanner) that way you will reach to the actual cause.
Other wise one can only tell you to check every thing one by one, and check if the check light goes off or not, thats a very lenthy and khuari procedure,
So its better that you get it scanned asap