We study a weighted eigenvalue problem with anisotropic diffusion in bounded Lipschitz domains Ω⊂RN, N≥1, under Robin boundary conditions, proving the existence of two positive principal eigenvalues λ± respectively associated with a positive and a negative eigenfunction. Next, we analyze the minimization of λ± with respect to the sign-changing weight, showing that the optimal eigenvalues Λ± are equal if the domain has a center of symmetry and the optimal weights are of bang-bang type, namely piece-wise constant functions, each one taking only two values. As a consequence, the problem is equivalent to the minimization with respect to the subsets of Ω satisfying a volume constraint. Then, we completely solve the optimization problem in one dimension, in the case of homogeneous Dirichlet or Neumann conditions, showing new phenomena induced by the presence of the anisotropic diffusion. The optimization problem for λ+ naturally arises in the study of the optimal spatial arrangement of resources for a species to survive in an heterogeneous habitat.