If the CEL is on for any reason the VTEC will not engage, and the engine will rev limit at about 5000. That is called "limp home" mode.
The problems you are experiencing are not related to each other though.
Probably your knock sensor is broken or disconnected. The ECU constantly checks it electrically even though the engine may not be knocking.
For idle problems start by checking the spark timing and bleeding the cooling system. If it's not that, try opening the air screw on the throttle body to keep idle up while the A/C is on. On the VTEC with horizontal throttle body it should be on the top front near where the big hose from the air cleaner attaches.