A work combining biological engineering, chemical science and energy storage application is demonstrated here. In particular, recombinant elastin-like polypeptides containing metal binding motifs (ELK16-FLAG) were constructed using genetic engineering techniques and were crosslinked to form a 3D porous matrix to direct the assembly of precursors. With the assistance of the ELK16-FLAG protein hydrogel template, a novel, facile and environmentally friendly synthesis approach is developed by successful synthesis of N,F co-doped three-dimensional porous carbon supported MnF2 nanocrystals (MnF2@N,F-C). Here, we used an ionic liquid (BmimBF4) to preserve the porous structure of the protein matrix, and serve as a fluorine source for carbon doping and the formation of MnF2 nanocrystals. After annealing at 600 °C in argon, three-dimensional N,F co-doped porous graphitized carbon-supported MnF2 nanocrystals (MnF2@N,F-C) were obtained. The annealed MnF2@N,F-C products were tested as anodes in rechargeable lithium ion batteries and high rate capabilities were obtained as a result of the nano-sized MnF2 crystallites and N/F-doping in the 3D graphitized structure.