In my thermodynamics/statistical mechanics book ("Concepts in thermal physics", Blundell), the temperature of a system A has been defined as being one over the derivative of the entropy of A with respect to the total (average) internal energy, evaluated at constant volume. This seems to imply that as long as a system has a well defined entropy and internal energy, then a temperature can be assigned by simply using this formula. But what if a system has a non-uniform temperature (meaning that it has no well-defined total temperature), but yet a well-defined entropy and internal energy? Doesn't this definition of temperature apply anymore in that case? This also get me to my second question. Can an entropy be assigned to a system with a non-uniform temperature? My guess is yes, since you can add up (or integrate, in the continuous case) all the entropies of various subsystems of A to get the total entropy. But at the same time, entropy is meant to be a state function which is only defined when the system is in a well-defined macroscopic state (which includes temperature??).
If the temperature is non-uniform, then the system is not at equilibrium and none of this applies.
The entropy (from the perspective of statistical mechanics - the number of microstates) is always well-defined (since is fundamentally combinatoric and does not depend on a given configuration of the system), but the temperature you obtain by this process is the temperature of the system, with a given energy $E$, when it finally reaches equilibrium.
You can eventually do this locally, if the system takes a long time to reach equilibrium, but it will only be an approximation.
Although the subject is called thermodynamics, it is more like thermostatics, since there is no dynamic (there is no time). The study of non-equilibrium thermodynamics (which is actually thermodynamics) and the definition of quantities, like the temperature, in these systems is a field of research.
Actually, you can easily notice that you need to be working in the context of equilibrium. The laws of thermodynamics imply that a system with non-uniform temperature eventually thermalize. This would introduce some notion of time, as you would need to label your quantities. The equilibrium properties are the only ones that do not depend on time.
Some people feel that it is valid to evaluate thermodynamic state properties locally (i.e., per unit mass), and I am one of them. In the case of temperature, for example, the partial derivative of specific internal energy with respect to specific entropy at constant specific volume would be the local temperature. Without assuming such local validity, it would be impossible to get accurate solutions to transient systems and steady flow systems experiencing transport processes. So we could never design heat exchangers, cooling towers, boilers, chemical reactors, distillation columns, absorption columns, piping systems, or any other industrial scale chemical processing equipment.
To add some references to the previous answers:
The very meaningful questions you are asking are addressed in the field of continuum thermomechanics, which studies the interplay of mechanical and thermal properties of generic bodies (systems) in generic dynamical processes.
Two beautiful books that introduce this theory are:
Müller, Müller: Fundamentals of Thermodynamics and Applications: With Historical Annotations and Many Citations from Avogadro to Zermelo (this beautiful book also studies thermodynamic systems such as droplets and rubber balloons).