A parish on the Upper West Side will stay open thanks to an agreement with developers and new affordable housing.