P0330 Knock Sensor 2 Circuit Malfunction- Well this could be either a defective, loose or a sensor condition (it detected something, usually no signal between 2000 to about 5600 RPM (though I can imagine 6000 in certain shift changes). A CEL here leads to what I have talked about before which is default or as Lexus likes to put it a fail-safe condition where the timing is retarded. However, this might just be a temporary condition, and that is why I recommend pulling the battery cables off to reset everything.
P0335 Crankshaft Position Sensor A Circuit Malfunction
Ideally the cranshaft position sensor or sometimes the starter (don't think so given the other condition above) and it occurs about 600 rpm officially though that can depend on certain use conditions, when no signal is detection from the crankshaft position sensor.
P0171- Yes, the ever popular lean error code. This is 90% likely an accompanying code, given that if one of the above occurs especially the first code mentioned, it alters Air/Fuel ratio readings and will trip that CEL, too. Doesn't necessarily mean a bad O2 sensor, bad MAF, etc. This is more than likely just a sensor reading that means the ratio was out of wack even for just moment.
I probably won't be able to get back to this until the evening as I have to prepare for an overseas trip for next week.