There is a subtle but important difference between the use of that and which in a sentence, and it has to do primarily with relevance. Grammarians often use the terms "restrictive" and "non-restrictive" when it comes to relative clauses. A relative clause provides additional information about the noun it describes, but it might be considered relevant or irrelevant to the overall point of the sentence. In other words, a restrictive relative clause, which often begins with that, is usually considered essential or restrictive. Relative clauses beginning with which might contain non-essential information and would be considered non-restrictive.
What might be more helpful in a person's daily quest for proper word usage are real examples containing that or which in their correct settings. What people need to keep in mind is the idea of restrictive or non-restrictive clauses, which translates to "necessary" or "helpful but non-essential."
In a sentence such as "The company that invented the microchip we use invited us to a demonstration," the word "that" is relative to "company." There are thousands of companies in the world, but it is important to know the "company that invented the microchip" is specifically the one holding the demonstration. In this sense, the relative clause beginning with that would be considered restrictive, since it is an essential piece of information needed to identify the company. A person would not write "The company which invented the microchip invited us to a demonstration." in formal writing.
Which could be used in a similar sentence constructed this way: "Widgets Incorporated, which invented the microchip we use, has officially declared bankruptcy." In this sentence, the relative clause "which invented the microchip we use" is separated by commas. The information about the microchip is useful, but not essential to the main idea of the sentence. It could be removed and the sentence would still make sense. If the relative clause can be removed without changing the sentence's meaning, it would be considered non-restrictive. Readers can identify the specific subject, in this case Widgets Incorporated, so "which" would be the correct pronoun to use. "Which" is almost always used to set off a non-restrictive relative clause, which can be remembered as a parenthetical phrase.
A sentence such as "Widgets Incorporated, that invented the microchip, has declared bankruptcy." would be incorrect. "That" does not usually set off a non-restrictive clause, since it is more closely related to the noun it modifies. The word "that" is rarely used in reference to people, as well. "The man that lost his hat yesterday found it this morning," would be incorrect. "The storage building that once stood on the corner has collapsed," would be correct, since "that" modifies an inanimate thing and the relative clause "that once stood on the corner" is restrictive and essential.
One might be tempted to use "which" in place of "that" in a similar sentence, such as "The building which used to be on the corner has been torn down.", but it would be incorrect. The information about the building's location is essential, so it would need a restrictive clause. A correct sentence using "which" would read like this: "The Olsen building, which stood on the corner of 12th and Vine Streets, has been torn down." The sentence could still be understood without the non-restrictive clause.
In short, whenever the information is essential to identifying the subject, the proper pronoun to use is that. If the information is not essential, or can be set apart with commas, then the pronoun which is more likely to be correct. As is the case with English grammar rules, however, there are going to be some exceptions to this rule. When in doubt, writers can try removing the relative clause and asking themselves if the sentence sounds complete and informative. Some grammar experts suggest silently adding the words "by the way" after which to determine if the information is relevant or irrelevant. If "by the way" seems to fit, then the clause is non-restrictive and should be set off with commas.
If the meaning of the sentence would be lost without the information, then it is most likely restrictive and that would be the proper pronoun to use.