Search Wikipedia:
Bi-directional sex change of marine fish
Written by Tim Wijgerde   
Did you know that many marine fish species can change sex when needed? Scientists found that the species P. flavivertex, P. aldabraensis and P. cyanotaenia can change sex in a single sex environment.
 
This basically means that when 2 females are placed together, one becomes male (or the other way around). When an individual changes from male to female, we call this protandry. When it changes from female to male, it is called protogyny.

 Pseudochromis aldabrahensis
Pseudochromis aldabraensis

Animals which display both male (testes) and female (ovaries) reproductive organs are called hermaphrodites. These fish are so-called sequential hermaphrodites, just like anemone fish (genera Amphirion and Frenatus), because they are not both male and female at the same time.

The aquaculture of marine fish benefits from this sex-change ability, which makes it less difficult to obtain a breeding pair. Unfortunately, the newly hatched fry requires zooplankton cultures to survive.

  Pseudochromis flavivertex
  Pseudochromis flavivertex

Another beautiful example of sequential hermaphroditism is displayed by dwarf angelfish (Centropyge spp.).  They change sex from female to male when the dominant male of the group is lost, thus they are protogynous species. When a male is lost from a harem, the largest female changes sex within a couple of weeks!

Recently, it was found that Centropyge ferrugata males change back to female after being dominated by a larger male. They reversed to a female state within 47-89 days. Not only did they change sex, their appearance changed as well. Angelfish display what is called sexual dichromatism, or sexual dimorphism. This means that males and females look different (humans are a very nice example). Male C. ferrugata angelfish have a specific colouration of the dorsal fin. After the male to female transition, even the dorsal fin changed back to that of a female.

Centropyge bispinosa

Centropyge bispinosa, Copyright the Wikimedia Foundation

Fish are remarkable creatures, and they have beautifully adapted to the harsh life in the oceans. Even when groups of fish do not have enough males, or females, many species simply change their sex to ensure reproduction. The sex change of all fish species is controlled by social interactions. Being dominant, or subordinate, controls sex hormone levels, and will trigger a change in sex in some situations.

References:

Wittenrich ML, Munday PL, Bi-directional sex change in coral reef fishes from the family Pseudochromidae: an experimental evaluation, Zoolog Sci. 2005 Jul;22(7):797-803

Sakai Y, Karino K, Kuwamura T, Nakashima Y, Maruo Y, Sexually dichromatic protogynous angelfish Centropyge ferrugata (Pomacanthidae) males can change back to females, Zoolog Sci. 2003, May;20(5):627-33.