A statistical mechanics approach to autopoietic immune networks