We consider here a nonlocal phase transition energy in a periodic medium and we construct solutions whose interfaces lie at a bounded distance from any given hyperplane. These solutions are either periodic or quasiperiodic, depending on the rational dependency of the normal direction to the reference hyperplane. Remarkably, the oscillations of the interfaces with respect to the reference hyperplane are bounded by a universal constant times the periodicity scale of the medium. This geometric property allows us to establish, in the limit, the existence of planelike nonlocal minimal surfaces in a periodic structure. The proofs rely on new optimal density and energy estimates. In particular, roughly speaking, the energy of phase transition minimizers is controlled, both from above and below, by the energy of one-dimensional transition layers.