There are a number of motivations to getting caught up on multiple years of unfiled taxes, but for many the impetus is buying a home! In these cases, it's often your lender seemingly calling the shots more than the IRS. However, lenders desire to do business with you often bumps up against the realities of the compliance demanded by the IRS. Let's review what lenders are looking at vs. the IRS:
Lenders are looking for three years of compliance. When applying for a home loan, if you file and pay your last three years of taxes, lenders are going to be pretty satisfied. (You should file electronically to expedite the processing and be prepared to pay penalties/interest.)
The IRS, however, is looking for six years of compliance. To truly be in the good graces of the IRS, you should file your last six years (and get into a payment plan or propose a settlement to IRS). But will three suffice? Perhaps...(depends on the IRS catching the years unfiled).
But what if you OWE taxes? If you owe taxes for three years and can't pay, you'll almost definitely need to expand your filing back to six years and then get into an installment agreement with the IRS. However, if you have the ability to full pay the IRS, you should do so. (if you are able to pay in full and also file the full six years, you can look at a penalty abatement/waiver.)
Can you buy a home and make a settlement with IRS at the same time? If you are in hardship situation and can't pay the IRS back or can't demonstrate that you can make payments, you probably shouldn't be in the market for a home(!). You should focus on settling with the IRS, then should your financial situation improve, then look at buying a home :)