Let's steal some techniques from other creatures and apply them here. It's unlikely that mermaids would evolve these methods, but then again, it's unlikely that a humanoid mermaid would evolve.
Texture and color change
The mimic octopus has an external organ system that allows it to accurately portray one of more than 15 aquatic species! It's composed of two main parts, both of which will be useful to you:
- Chromatophores are small sacs of pigments that can be controlled by some octopuses to adjust color. Mermaids don't need more than two groups of pigments - one for scales, if you so desire, and the other containing normal skin pigments - but you are welcome to include more if you want color-changing tails.
- An additional organ or system of muscles that allows the skin to completely change shape and texture. Your mermaids can have an adapted version of this system, which - instead of being used for disguises - will switch between two states, scales and flesh, depending on which they prefer.
Physically making fins
Flying fish extend large, wing-like appendages only when needed - otherwise, they're drawn relatively close to the body. While this is not the best example, you could consider keeping the end of the tail all along, but retracting and folding it into a crease in the skin (or a slit-like organ) when not in use. While you could probably find a way to make a new tail fin every time, it's most feasible to hide it elsewhere.
For this process, it will be easiest to have thinner, flexible feet - or more poseable ankle joints.
Joining the legs
There aren't many animals that physically "join" two of their limbs - besides some octopi, which push them close together, but do not fully "join" anything.
Consider combining the ability to change texture, described above, with powerful reflexes and muscles to keep the legs as watertight - and streamlined - as possible.
Breathing
This is relatively simple. Three approaches will work well:
- Combining both lungs and gills on the same body. This will allow efficient breathing in either phase, and Australian lungfish are able to do just that.
- Relying only on lungs. Similarly to whales, dolphins, and several other species, you may not need to develop gills at all.
- Breathing through the skin, which may work both above and below the water. Several amphibians are able to do so; it's not unrealistic to adapt that system, although it may be visible from the outside.