The geometry of profinite graphs with applications to free groups and finite monoids