Trim codes, especially if they've been long term issues, can damage 02 sensors and cats, so I hope you haven't been ignoring stuff for a real long time.
Check for air leaks first. Hoses are inexpensive to fix, just a little time consuming to find.
Yes, I think that trim codes might be why you failed emissions. Read jfoj's sig link. Search for jfoj and read the link he has on 'solving misfires'
dmax on the radio--answering all your car questions as best I can!
watsonnwatson.com every Wednesday at 9 p.m. NYC time. Call in! (661) 449-9340 Click "Watch and Chat"
Please 'friend' me!