The knock sensor is a microphone for the ecu. If it hears the engine knocking, the ecu will pull timing to stop that from happening. Eventually, the ecu will slowly add that timing back as you continue driving. The knock sensor has no other function, and can not advance timing.
To answer your question above, timing is where the power is. First you get the A/F where you want it using a wideband, then you start advancing the timing little by little. You stop when it either knocks, or stops making power. A knock sensor is helpful when tuning because you can see where the ecu thought there may be knock, and pulled timing. That will show up as a dip on the power graph.
That is a very shortened version of how the knock sensor helps when tuning.