Generalization of homotopy groups: can we replace $S^n$ by other spaces? For a given topological space $X$, the fundamental group $\pi_1(X)$ is defined by homotopy equivalence classes of continuous map $f : S^1 \to X$. Similarly, the $n^{\text{th}}$ homotopy group $\pi_n(X)$ is defined by homotopy equivalence classes of $f : S^n \to X$. My question is, can we generalize this concepts by replacing $S^1$ or $S^n$ to other spaces, such as projective spaces or Grassmanians? 
 A: Short Answer: You can, but you might lose the group structure.

Your definitions of $\pi_1(X)$ and $\pi_n(X)$ are not correct - you're missing basepoints.
Fix a basepoint $p \in S^n$ and let $X$ be a topological space. Given $x_0 \in X$, $\pi_n(X, x_0)$ is the collection of maps $f : S^n \to X$, with $f(p) = x_0$ (often called pointed maps) up to homotopy relative to $\{p\}$ (sometimes called basepoint-preserving homotopy). 
For $n = 0$, $\pi_0(X, x_0)$ can be identified with the set of connected components of $X$; it is independent of the choice of basepoint $x_0$ so we just write $\pi_0(X)$. If $X$ is path-connected, then for $n \geq 1$, $\pi_n(X, x_0)$ is independent of $x_0$ and we just write $\pi_n(X)$; if $X$ is not path-connected, $\pi_n(X, x_0) = \pi_n(C)$ where $C$ is the path-connected component of $X$ containing $x_0$.
Moving towards your question, if $Y$ and $Z$ are pointed spaces, denote the collection of basepoint-preserving homotopy classes of pointed maps $Y \to Z$ by $[Y, Z]_{\bullet}$. With this notation, we see that $\pi_0(X) = [S^0, X]_{\bullet}$, and if $X$ is path-connected $\pi_n(X) = [S^n, X]_{\bullet}$ for $n \geq 1$ (if $X$ is not path-connected, $[S^n, X]_{\bullet} = \pi_n(C)$ where $C$ is the path-connected component of $X$ containing $x_0$).
If you fix a pointed topological space $A$, then for any other pointed topological space $X$, $[A, X]_{\bullet}$ is a well-defined set you may wish to study. If you're willing to accept the Axiom of Choice, then any non-empty set can be equipped with a group structure (in fact, this is equivalent to the Axiom of Choice). Now $[A, X]_{\bullet}$ will always be non-empty (it contains the equivalence class of the constant map from $A$ to the basepoint of $X$), so it can be equipped with a group structure, but not in a natural way. First of all, there could be more than one group structure to put on a set of a given cardinality, which one do you choose? On the other hand, the group structure on $\pi_n(X)$ is constructed in a way that doesn't depend on $X$ - it is natural in $X$. That is, if $Y$ is another pointed space and $g : X \to Y$ is a pointed map, there is an induced map $g_* : \pi_n(X) \to \pi_n(Y)$ given by $[f] \mapsto [g\circ f]$ which is a homomorphism of groups. As this is a useful property, you may want to require the same of the groups $[A, X]_{\bullet}$. 
A pointed topological space $A$ such that $[A, X]_{\bullet}$ is a group for every $X$, and the group structure is natural in $X$ (in the previous sense), is precisely a cogroup object in $\mathsf{hTop}_{\bullet}$, the homotopy category of pointed topological spaces - such a space is sometimes called an $H$-cogroup. More generally, a cogroup object in a category $\mathsf{C}$ is an object $A$ such that $\operatorname{hom}_{\mathsf{C}}(A, X)$ is a group for every object $X$, and the group structure is natural in $X$.
From the above, we know that the spheres $S^n$ for $n \geq 1$ are cogroup objects in $\mathsf{hTop}_{\bullet}$, but $S^0$ isn't ($\pi_0(X)$ is just a set). You may hope that there are other cogroup objects, and there are. For any pointed topological space $B$, its reduced suspension $\Sigma B$ is a cogroup object in $\mathsf{hTop}_{\bullet}$ - this is why spheres $S^n$ for $n \geq 1$ are examples, because $S^n = \Sigma S^{n-1}$. While suspensions provide many examples of cogroup objects, there are cogroup objects which are not suspensions.
You asked about projective spaces and Grassmannians. Of course, these will give rise to sets, but are they cogroup objects in $\mathsf{hTop}_{\bullet}$? It turns out that the answer is no. In fact, the only (positive-dimensional) compact connected manifolds which are cogroup objects are spheres.
