Ferromagnetic materials exhibit a long-range ordering phenomenon at the atomic level which causes the unpaired electron spins to line up parallel with each other in a region called a domain. Within the domain, the magnetic field is intense, but in a bulk sample the material will usually be unmagnetized because the many domains will themselves be randomly oriented with respect to one another. Ferromagnetism manifests itself in the fact that a small externally imposed magnetic field, say from a solenoid, can cause the magnetic domains to line up with each other and the material is said to be magnetized. The driving magnetic field will then be increased by a large factor which is usually expressed as a relative permeability for the material. There are many practical applications of ferromagnetic materials, such as the electromagnet.
Ferromagnets will tend to stay magnetized to some extent after being subjected to an external magnetic field. This tendency to "remember their magnetic history" is called hysteresis. The fraction of the saturation magnetization which is retained when the driving field is removed is called the remanence of the material, and is an important factor in permanent magnets.
Within this framework, your statement
When the iron bar is no longer attracted by the permanent magnet, it is no longer a magnet itself because its magnetic domains point in different directions again.
is not true. Some magnetization remains, depending on the material and its characteristics. It is called the hysteresis of the material.
When iron is heated up to curie temperature and cooled down all of its magnetic domains also start to point in the same direction. ( If I am not wrong the atomic structure does not change)
Note: if there exists a magnetic field to line up against, otherwise it will be random.
So why is it permanent in the second case and not in the first ? (Correct me if I messed up something here)
Permanence depends on the hysteresis characteristics of the material as it responds to an external magnetic field.
At atomic dimensions, the domain model, see figure and links, explains what happens. Domains get energy from external fields to orient in the direction of the field, and depending on the magnetic characteristics of the unpaired electron spins in the domain, can remain there, in a metastable state, until energy is supplied to move them again, (as heat or another magnetic field).