Optimization of the thermoelectric properties of nanostructured silicon