The hard line (first photo) looks to be from from the vapor canister purge valve (under the battery) and should go to the throtle body. On my engine there is a white plastic retaining clip that slides to lock the line on the throttle body once attached.
Make sure the connector is all the way down on the temp sensor or it won't read properly, make sure the wires to the sensors aren't reversed. Code 0340 might be that you didn't re-connect the CPS sensor wiring on the block behind the intake: