Multivalent batteries show promising prospects for next-generation sustainable energy storage applications. Herein, we report a polytriphenylamine (PTPAn) composite cathode capable of highly reversible storage of tetrakis(hexafluoroisopropyloxy) borate [B(hfip)$_4$] anions in both Magnesium (Mg) and calcium (Ca) battery systems. Spectroscopic and computational studies reveal the redox reaction mechanism of the PTPAn cathode material. The Mg and Ca cells exhibit a cell voltage >3 V, a high-power density of ~3000 W kg$^{−1}$ and a high-energy density of ~300 Wh kg$^{−1}$, respectively. Moreover, the combination of the PTPAn cathode with a calcium-tin (Ca-Sn) alloy anode could enable a long battery-life of 3000 cycles with a capacity retention of 60%. The anion storage chemistry associated with dual-ion electrochemical concept demonstrates a new feasible pathway towards high-performance divalent ion batteries.