The knock sensor code will be unlikely to be causing this. It could be so many things its hard to say without being able to do some basic diagnostic tests to see what is going on. Its important to start with basics (knowing the engine is sound, good even compression ect....), To find an intermittent problem like this I "tee into" the fuel line and tape a fuel pressure gauge to the windscreen so I can monitor fuel pressure when the problem occurs, if fuel pressure falls off, or drops to zero you know your problem is fuel related, you then start tracing the fuel pump, fuel pump relay and sensors that allow for fuel pump operation. I also drive around with a timing light attached to one of the spark plug wires, when the vehicle falters I pull the trigger on the timing light and see if I have spark. If the there is no spark I check the ignition system, wiring and sensors associated with the ignition system. Intermittent problems are hard to find and your vehicle has limited diagnostic capabilities. If the engine has computerized engine idle control, the computer in your car constantly monitors the speed of the engine and tries to maintain an idle speed based on engine temperature, and "load" on the engine, if the computer senses the idle speed is too low it automatically raises the engine speed to prevent the engine from stalling but it can only compensate so much! A problem in the idle speed control system can obviously be a cause for an engine to stall and cut out. Understanding how each system works, having a good wiring diagram and volt/ohm meter and patience are required to trouble shoot this kind of problem.
There is a company that independent auto repair shops get their information from, this same information is available inexpensively for people that work on their own cars.. The information is year make and model specific, covering repair procedures, torque specifications, fluid capacities and specifications, service bulletins, component locations, wiring diagrams ect.... Alldata is very easy to navigate http://bit.ly/AllData_Repair_Manuals_Online