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.
If you buy insurance for only four days, what happens if your return flight is delayed and you slip and break your leg in the airport a few hours into day five?
You need travel and medical insurance for the full duration of your trip including any unexpected delays.