I am behind on my mortgage. Can I file for bankruptcy and still keep my house?

Yes. You can use a chapter 13 plan to pay the arrears or past due amount on the loan over a period of 3-5 years, while simultaneously making the contractual prospective monthly payment.  Another option under chapter 13 is to apply for a modification while in bankruptcy and withhold paying the arrears on the mortgage.  You can remain under bankruptcy protection until a decision is reached with the lender.  If the lender agrees to modify, chances are you will not have pay back the arrears through the chapter 13 plan.