Anaerobic treatment of chemical wastes