assume 401k limit 17,000
tax rate 28%
forget about annual return, say you make zero
the opportunity cost 17K*0.28=4760
VS.
30y Loan on after-tax money 17K*(1-0.28)=12,240
assume 4% rate, monthly payments $58.44, total 30Y interest saved $8,797, however, you don't get the benefit of tax deduction so opportunity cost is 8,797*(1-0.28)=6,334
HOWEVER, the savings of 30Y loan in terms of interests is for ENTIRE 30Y, while opp cost of 401k, is only one year. In order to max out net worth, 401K is the best choice.
By taking out 401K you get hurt twice, first on tax deduction of 401K, second on the tax-dedutible interest.