  We study $321$-avoiding affine permutations, and prove a formula for their
enumeration with respect to the inversion number by using a combinatorial
approach. This is done in two different ways, both related to Viennot's theory
of heaps. First, we encode these permutations using certain heaps of monomers
and dimers. This method specializes to the case of affine involutions. For the
second proof, we introduce periodic parallelogram polyominoes, which are new
combinatorial objects of independent interest. We enumerate them by extending
the approach of Bousquet-M\'elou and Viennot used for classical parallelogram
polyominoes. We finally establish a connection between these new objects and
$321$-avoiding affine permutations.
