Well, with the 24 and 31 it's either a bad KVAF or a short in the wiring harness.
The code 51, as stated in the TSRM, is often caused by someone hitting the throttle while the car is in the diagnostic mode or the A/C running at that time... less common is the possibility of a bad IDL switch in the TPS, bad switch in the A/C circuit or a fault in the wiring harness.
Knock codes come up for one of three reasons: knock, bad sensors or bad wiring...
No, the air leak shouldn't cause any of those codes.
Cygnus X1 Home Page
Note the links at the top right: TSRM (Toyota Service & Repair Manual), EPC (Electronic Parts Catalog), TEWD (Toyota Electronics & Wiring Diagrams)