As for the upgrade only in cities, I swear I played a mod that had that but I cannot remember which one.
you could add to the PreReqBuilding tag in the unitinfos.xml for the building part, for the upgrade only part you may be able to do iCost = -1, though not sure how that would affect the upgrade cost
No, all you need is for the unit to require a certain building in order to be built, just like the Monastery. It won't upgrade unless you bring it back to a city with that particular building. I discovered that when experimenting with having a building requirement for every unit. I dropped that idea because it made upgrading too much of a pain. It's also going to be a handicap for the AI since it won't know that it has to move a unit to a city to upgrade.