"So you're saying the CO is caused by an excessively rich mixture; possibly caused by a bad 02 sensor. The hydrocarbons are caused by another problem, but probably not the EGR system. The other problem may be a misfire..."
Both high HC and high CO are caused by insufficient oxygen in the combustion, or insufficient oxidation in the cat. An engine running lean to reduce both also produces high peak combustion temperatures - and the result of this is an increase in NOx. The EGR valve leaks some exhaust gas back into the intake, and this reduces the combustion temperatures, and thus the NOx.
So, it is reasonable that the same source of your high CO is causing the high HC also. Find why your ECU is out of loop control, and that will likely sove your problem. Note that the O2 sensor is the primary feedback device, but the ECU will also not function if it can't detect engine speed, throttle opening, airflow or any of a select group of other input devices.