Both in vivo and in vitro, specific sequences in double-stranded DNA can adopt the left-handed Z-form when underwound. Recently, the B-Z transition of DNA has been studied in detail in magnetic tweezers experiments by several groups. We present a theoretical description of this transition, based on an annealed random copolymer model. The transition of a switchable sequence is discussed as a function of energetic and geometric parameters of the B- and Z-forms, of the applied boundary conditions, and of the characteristics of the B-Z interface. We address a possible torsional softening upon the B-Z transition. The model can be also applied to other biofilaments with annealed torsional/flexural degrees of freedom.