While writing out the electronic configurations, we usually write them in the order of 1s 2s 2p 3s 3p 3d 4s 4p 4d 4f 5s 5p 5d 5f and so on. This method of writing the electronic configuration only represents the traditional increasing order of shells ( 1 2 3 4 or K L M N ), and nested within each shell are the subshells ( s p d f).
This is only the usual method of writing the electronic configurations; it does not reflect the order of increasing energy of orbitals. The order of energy is given by the Aufbau's Principle or the building-up priciple.
In essence, according to the rule, for comparing energies of orbitals of all elements, except hydrogen, we compare the values of the sum of (n+l) ; where n is the priciple quantum number ( corresponding to K=1 L=2 N=3 etc. ) and l is the azimuthal quantum number ( corresponding to s=0 p=1 d=2 etc. ). Greater the value of this sum, more is the (relative) energy associated with that orbit. Moreover, if this sum is same for two orbitals, then we compare the value of n for those orbitals.
So, for example, you mentioned the anomaly in the energy order of 4s and 3d. Using this rule, for 4s we have n=4 & l=0, giving a sum of 4, while for 3d we have n=3 & l=2, giving a sum of 5. This gives us a greater energy for 3d, which shows us that it confirms to the rule rather than being anomalous.
Further, consider the case of 4s and 3p orbitals; the n+l sum is same for both (4 in each case), but since 4s has a greater value of n than 3p , it is more energetic.
Now, electronic configurations are important in the order 1s 2s 2p 3s 3p 3d 4s 4p 4d 4f 5s 5p 5d 5f when we are considering cases of ionization ; so, if you want to make a +2 ion, of say, Fe, then the two electron will be removed from the outermost orbitals, i.e. 4s. However, in cases where we are concerned with the actual energies, we must subscribe to the Aufbau's Principle.