Alloy materials have received recent attention in the context of high-capacity and high-rate anodes for lithium and sodium-ion batteries. Here, we will present a first principles structure prediction study combined with NMR and molecular dynamics calculations which give us in- sights into the lithiation/sodiation process of phosphorus and tin anodes. We report a variety of new stable and metastable phases found by the ab initio random structure searching (AIRSS) and atomic species swapping methods, which help us to elucidate experimental observations. We identify that specific ranges in the calculated chemical shifts can be associated with specific ionic arrangements, results which play an important role in the interpretation of in operando NMR spectroscopy experiments. Since the lithium-phosphides are found to be insulating even at high lithium concentrations we show that Li-P-doped phases with aluminium have electronic states at the Fermi level suggesting that using aluminium as a dopant can improve the electrochemical performance of P anodes.