I'm going for a conference which would last 4 days. Should I buy travel insurance for the whole 3 months of my Schengen visa or just the length of my stay (4 days)?
You buy insurance for the duration of the trip.
You do not need travel insurance for a time when you have a valid visa but are in your home country.
If you are delayed a day or so the insurance is normally extended to cover it, though you should make sure that is the case, or maybe buy insurance that covers five or six days. If your return is delayed for medical reasons your medical insurance should cover that.