All things considered, an “okay” house in a great area will likely produce the best financial return. However, residential real estate decisions aren’t made in a vacuum and there can be tradeoffs (this creates the concept of "value").
For example, an okay house in a great area is probably one that hasn't much been upgraded to “modern” standards, so you run the risk of a higher level of upgrade and maintenance costs. Renovating bathrooms, kitchens and outdoor areas can run big money and because of this, the price of an okay home is likely discounted relative to its neighborhood companions.
That said, some people buy homes on the basis of "potential" -- that is, what a house or piece of property could be after an upgrade cycle is completed. If you can score an okay home in a great area and have the wherewithal to improve it so it becomes a great home in a great area, that's fantastic; lots of people look to do this. However, if you don't have the funds to do this, you will still have just an okay home in a great area (there's nothing wrong with this, of course).
However, if this choosing just an okay house means you aren't getting what you really want out of your home for yourself and your family, you may end up being unsatisfied with your choice. For example, if buying an okay home in a great area means no garage, or walk-out basement, or other feature that is important to you, you may not be all that happy, even as your financial self will likely feel satisfied.
Conversely, a great home in an okay area runs risks that are nearly reversed. Without a great area to help support the value, you run the risk that the financial side of the transaction won't work out in your favor. Arguably, you'll need to do all the "heavy lifting" to make certain that your home holds or increases in value, as the surrounding neighborhood or community won't be contributing much in this way. Of course, if you end up getting all of the house you really need or want, it's a good bet that you will be highly satisfied with your ownership, even as you might have to travel farther to stores, schools, entertainment and to see friends living in homes not as nice as yours.
For most of us, housing and residential real estate is all about compromise; it's an intersection of trying to find the best available house with the greatest number of needed and wanted features in the best available location with the most desirable amenities at a price that is affordable. For existing homes, all this occurs in a market where you have zero control or what is available to buy; for new homes, you have a greater level of control over what goes into the house, but probably less so over where the property will be located. In the end, it's all about tradeoffs and compromises, meeting needs and wants, and assessing weighing what's important to you and your family.