When to use Which and when to use that?

You use "which" if it is something nonessential to the sentence, and you use "that" when it is essential. Anything with a "which" should be set off by commas, but anything with a "that" should not.

Examples:

The dinner, which was quite tasty, was not very long.

The dinner that we had at Wendy's was not very elegant.