Heat the oven to 375°.
In a large skillet, sauté the onion and mushrooms in the oil over medium-high heat until softened, about 5 minutes. Add the salt and pepper.
Squeeze the spinach to remove as much liquid as possible. In a large bowl, stir together the spinach, the cooked onions and mushrooms, the cottage cheese, grated cheeses, and pimientos. Mix in the eggs and flour.
Pour the mixture into a lightly greased 2 1/2-quart casserole and bake for 45 minutes.