Do you have the MAF from the old engine? I would try swapping them since cleaning it changed the behavior. There are degrees of failure, not just good or bad, so rough idle after disconnecting it doesn't necessarily mean that it's not failing.
An easy swap and good place to start

This would also explain O2 codes.