Somali pirates have released a Greek-owned cargo ship and its 24 Ukrainian crew members after seven months in captivity .