Optimal charging of a quantum battery consisting of electron spin qubits