Let K be a commutative ring with unity, R a prime K-algebra of characteristic different from 2, Z(R) the center of R, f(x(1),...,x(n)) a non-central multilinear polynomial over K, d and delta derivations of R, a and b fixed elements of R. Denote by f(R) the set of all evaluations of the polynomial f(x(1),...,x(n)) in R. If a[d(u), u] + [delta(u), u]b = 0 for any u is an element of f(R), we prove that one of the following holds: (i) d = delta = 0; (ii) d = 0 and b = 0; (iii) delta = 0 and a = 0; (iv) a, b is an element of Z(R) and ad + b delta = 0. We also examine some consequences of this result related to generalized derivations and we prove that if d is a derivation of R and g a generalized derivation of R such that gad(u), up = 0 for any u is an element of f(R), then either g = 0 or d = 0.