1. When the "which" clause refers to the whole preceding sentence:
"He punched me in the jaw and knocked me out, which I wasn't happy about.
2. Before a non-defining relative clause, as in your first example, and possibly the second. (I think the second example could go either way).
A defining relative "which" clause answers a "Which?" question.
"Which townhouse? The townhouse which will serve as a display shop"
A non-defining clause adds information, but does not define which townhouse you are referring to.
"We are building a townhouse, which will serve as a display shop."
"The orange tie which my wife bought me looks silly" (Answers "which tie?" from a sample of orange ties - the one which my wife bought me)
"The orange tie, which my wife bought me, looks silly." (Does not define which tie, but merely adds information.)